繁体   English   中英

在 Python 环境中设置 NLTK 的问题

[英]Issues Setting Up NLTK within Python Environment

我是编程新手,我正在尝试下载 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 (须藤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

我通过升级 setuptools 解决了这个问题: pip install setuptools -U --user

您可能不需要--user ,我需要它,因为没有它我会遇到权限错误。

出现这个问题是因为s​​etuptools版本较低,可以分三步解决。

要检查 setuptools 版本:

python -c "import setuptools; print setuptools.__version__"

1.升级到最新版本的setuptools:

 sudo pip install -U setuptools

要检查 setuptools 版本:

python -c "import nltk; print nltk.__version__"

2. 升级或安装 nltk 最新:

sudo pip install -U nltk

3.检查nltk模块:

>>> import nltk

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM