简体   繁体   English

在 Python 环境中设置 NLTK 的问题

[英]Issues Setting Up NLTK within Python Environment

I am new to programming and I am in the process of attempting to download NLTK to work on a chatbot with Python.我是编程新手,我正在尝试下载 NLTK 以使用 Python 在聊天机器人上工作。 At the moment, I am running Python 2.7.目前,我正在运行 Python 2.7。 As per the documentation for the NLTK available, "NLTK requires Python versions 2.7, 3.5, 3.6, or 3.7."根据可用的 NLTK 文档,“NLTK 需要 Python 版本 2.7、3.5、3.6 或 3.7。”

I downloaded Homebrew and ran the commands the documentation suggested, but have gotten error messages.我下载了 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$ 

Per the documentation available at: https://www.nltk.org/install.html根据以下提供的文档: https : //www.nltk.org/install.html

I attempted the " sudo pip install -U nltk" command, which returned the errors:我尝试了“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/

I also tried the suggestion on the bottom of the documentation page with no luck, specifically "For older versions of Python it might be necessary to install setuptools (see http://pypi.python.org/pypi/setuptools ) and to install pip (sudo easy_install pip)."我还尝试了文档页面底部的建议,但没有运气,特别是“对于旧版本的 Python,可能需要安装 setuptools(请参阅http://pypi.python.org/pypi/setuptools )并安装 pip (须藤easy_install pip)。” The following errors resulted:导致以下错误:

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/

Your help is much appreciated!非常感谢您的帮助! Many thanks from Jupiter, FL, USA!非常感谢来自美国佛罗里达州木星的感谢!

尝试运行sudo -H pip3 install -U nltk

I resolved this by upgrading setuptools: pip install setuptools -U --user我通过升级 setuptools 解决了这个问题: pip install setuptools -U --user

You might not need the --user , I needed it because I got a permission error without it.您可能不需要--user ,我需要它,因为没有它我会遇到权限错误。

This issue occurs because of lower version of setuptools, you can solve this in three steps.出现这个问题是因为s​​etuptools版本较低,可以分三步解决。

To check the setuptools version:要检查 setuptools 版本:

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

1. Upgrade to latest version of setuptools: 1.升级到最新版本的setuptools:

 sudo pip install -U setuptools

To check the setuptools version:要检查 setuptools 版本:

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

2. Upgrade or Install nltk latest: 2. 升级或安装 nltk 最新:

sudo pip install -U nltk

3.Check the nltk module: 3.检查nltk模块:

>>> import nltk

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

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