繁体   English   中英

无法使用 Python 3.7 安装 NLTK

[英]Unable to install NLTK with 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,但这没有任何意义。 我究竟做错了什么?

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

  1. 在虚拟环境中升级pip

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

     . .env/bin/activate pip install nltk

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

  1. 首先,您必须使用此命令升级您的 pip

    python -m pip install –upgrade pip

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

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

  3. 然后运行这个命令

    pip3 install nltk

希望它会奏效!

暂无
暂无

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

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