python - 在 Python 环境中设置 NLTK 的问题
问题描述
我是编程新手,我正在尝试下载 NLTK 以使用 Python 在聊天机器人上工作。目前,我正在运行 Python 2.7。根据可用的 NLTK 文档,“NLTK 需要 Python 版本 2.7、3.5、3.6 或 3.7。”
我下载了 Homebrew 并运行了文档建议的命令,但收到了错误消息。
Leonas-MacBook-Air:~ leonaadriennestephanieponce$ sudo pip install -U nltk
Password:
Sorry, try again.
Password:
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
WARNING: The directory '/Users/leonaadriennestephanieponce/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
WARNING: The directory '/Users/leonaadriennestephanieponce/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting nltk
Downloading https://files.pythonhosted.org/packages/73/56/90178929712ce427ebad179f8dc46c8deef4e89d4c853092bee1efd57d05/nltk-3.4.1.zip (3.1MB)
|████████████████████████████████| 3.1MB 548kB/s
ERROR: Complete output from command python setup.py egg_info:
ERROR: error in nltk setup command: 'install_requires' must be a string or list of strings containing valid project/version requirement specifiers; Expected version spec in singledispatch; python_version < "3.4" at ; python_version < "3.4"
----------------------------------------
ERROR: Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-install-OTcEsN/nltk/
Leonas-MacBook-Air:~ leonaadriennestephanieponce$ sudo easy_install pip
Password:
Sorry, try again.
Password:
Sorry, try again.
Password:
Searching for pip
Best match: pip 19.1.1
Processing pip-19.1.1-py2.7.egg
pip 19.1.1 is already the active version in easy-install.pth
Installing pip script to /usr/local/bin
Installing pip2.7 script to /usr/local/bin
Installing pip2 script to /usr/local/bin
Using /Library/Python/2.7/site-packages/pip-19.1.1-py2.7.egg
Processing dependencies for pip
Finished processing dependencies for pip
Leonas-MacBook-Air:~ leonaadriennestephanieponce$ sudo pip install -U nltk
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
WARNING: The directory '/Users/leonaadriennestephanieponce/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
WARNING: The directory '/Users/leonaadriennestephanieponce/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting nltk
Downloading https://files.pythonhosted.org/packages/73/56/90178929712ce427ebad179f8dc46c8deef4e89d4c853092bee1efd57d05/nltk-3.4.1.zip (3.1MB)
|████████████████████████████████| 3.1MB 465kB/s
ERROR: Complete output from command python setup.py egg_info:
ERROR: error in nltk setup command: 'install_requires' must be a string or list of strings containing valid project/version requirement specifiers; Expected version spec in singledispatch; python_version < "3.4" at ; python_version < "3.4"
----------------------------------------
ERROR: Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-install-vY99RW/nltk/
Leonas-MacBook-Air:~ leonaadriennestephanieponce$
根据提供的文档:https ://www.nltk.org/install.html
我尝试了“sudo pip install -U nltk”命令,它返回了错误:
ERROR: Complete output from command python setup.py egg_info:
ERROR: error in nltk setup command: 'install_requires' must be a string or list of strings containing valid project/version requirement specifiers; Expected version spec in singledispatch; python_version < "3.4" at ; python_version < "3.4"
----------------------------------------
ERROR: Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-install-OTcEsN/nltk/
我还尝试了文档页面底部的建议,但没有成功,特别是“对于旧版本的 Python,可能需要安装 setuptools(请参阅http://pypi.python.org/pypi/setuptools)并安装 pip (sudo easy_install pip)。” 导致以下错误:
ERROR: Complete output from command python setup.py egg_info:
ERROR: error in nltk setup command: 'install_requires' must be a string or list of strings containing valid project/version requirement specifiers; Expected version spec in singledispatch; python_version < "3.4" at ; python_version < "3.4"
----------------------------------------
ERROR: Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-install-vY99RW/nltk/
非常感谢您的帮助!非常感谢来自美国佛罗里达州朱庇特的感谢!
解决方案
尝试运行sudo -H pip3 install -U nltk
推荐阅读
- android - Android JetPack 的共享 ViewModel 生命周期
- button - 在 Xamarin 表单中使用带有图像和文本的按钮
- react-native - 如何调用 Actions.pop() 并刷新上一个场景?React Native、Redux、React-Native-Router-Flux
- javascript - 将对象数组转换为数组数组?
- java - 无法删除 recyclerview 项目
- android - 缩放画布后坐标错误
- java - Spring JDBC:即使将行插入表中,也不返回自动生成的id
- laravel - 如何在 laravel 5.6 中获取配置值
- java - 如何在组件扫描期间避免 Spring 中不需要的 bean?
- python - 计算有多少演员与其他不同的演员/演员合作过