无法使用Python 3.7安装NLTK

时间:2019-09-29 05:35:09

标签: python nltk python-3.7

NLTK文档说它支持Python 3.7。但是,当我尝试通过以下方式安装它时:

virtualenv -p python3.7 .env
. .env/bin/activate
pip install nltk

我得到了错误:

Collecting nltk
  Using cached https://files.pythonhosted.org/packages/f6/1d/d925cfb4f324ede997f6d47bea4d9babba51b49e87a767c170b77005889d/nltk-3.4.5.zip
    ERROR: Command errored out with exit status 1:
     command: /path/to/my/project/.env/bin/python3.7 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-12ut35ws/nltk/setup.py'"'"'; __file__='"'"'/tmp/pip-install-12ut35ws/nltk/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
         cwd: /tmp/pip-install-12ut35ws/nltk/
    Complete output (1 lines):
    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 errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

错误消息听起来像NLTK仅支持Python <3.4,但这没有任何意义。我在做什么错了?

2 个答案:

答案 0 :(得分:2)

这是因为distutils不支持软件包格式,这表明软件包工具可能太旧了。

  1. 在虚拟环境中升级pip

    pip install -U pip
    pip install -U setuptools
    
  2. 重试安装nltk

    . .env/bin/activate
    pip install nltk
    

如果仍然不起作用。提供来自pip install nltk -v的日志。

答案 1 :(得分:0)

  1. 首先,您必须使用此命令来升级点子

    python -m pip install –upgrade pip

  2. 首先,您必须导航到pip文件夹的位置

    C:\Users\Admin>cd C:\Python\Scripts

  3. 然后运行此命令

    pip3 install nltk

希望它能工作!