【问题标题】:Errrors while installing NLTK安装 NLTK 时出错
【发布时间】:2020-05-27 10:31:18
【问题描述】:

在尝试通过pip install nltk 安装 NLTK 时出现以下错误


  ----------------------------------------
  Failed building wheel for nltk
  Running setup.py clean for nltk
  Running setup.py bdist_wheel for regex ... error
  Complete output from command /home/pavan/Desktop/chatbot/myenv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-s1j858so/regex/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d /tmp/tmp01krw6rjpip-wheel- --python-tag cp35:
  usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
     or: -c --help [cmd1 cmd2 ...]
     or: -c --help-commands
     or: -c cmd --help

  error: invalid command 'bdist_wheel'

  ----------------------------------------
  Failed building wheel for regex
  Running setup.py clean for regex
Failed to build nltk regex
Installing collected packages: regex, tqdm, nltk
  Running setup.py install for regex ... error
    Complete output from command /home/pavan/Desktop/chatbot/myenv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-s1j858so/regex/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-5loncafz-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/pavan/Desktop/chatbot/myenv/include/site/python3.5/regex:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.5
    creating build/lib.linux-x86_64-3.5/regex
    copying regex_3/__init__.py -> build/lib.linux-x86_64-3.5/regex
    copying regex_3/regex.py -> build/lib.linux-x86_64-3.5/regex
    copying regex_3/_regex_core.py -> build/lib.linux-x86_64-3.5/regex
    copying regex_3/test_regex.py -> build/lib.linux-x86_64-3.5/regex
    running build_ext
    building 'regex._regex' extension
    creating build/temp.linux-x86_64-3.5
    creating build/temp.linux-x86_64-3.5/regex_3
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/pavan/Desktop/chatbot/myenv/include -I/usr/include/python3.5m -c regex_3/_regex.c -o build/temp.linux-x86_64-3.5/regex_3/_regex.o
    regex_3/_regex.c:48:20: fatal error: Python.h: No such file or directory
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

    ----------------------------------------
Command "/home/pavan/Desktop/chatbot/myenv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-s1j858so/regex/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-5loncafz-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/pavan/Desktop/chatbot/myenv/include/site/python3.5/regex" failed with error code 1 in /tmp/pip-build-s1j858so/regex/
You are using pip version 8.1.1, however version 20.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

为了解决错误error: command 'x86_64-linux-gnu-gcc' failed with exit status 1,我尝试了sudo apt-get install python3-dev,如另一篇stackOverflow帖子中所示,但得到了错误

E: Malformed entry 4 in list file /etc/apt/sources.list.d/additional-repositories.list (Component)
E: The list of sources could not be read.
E: Malformed entry 4 in list file /etc/apt/sources.list.d/additional-repositories.list (Component)
E: The list of sources could not be read.

谁能解释一下出了什么问题以及什么是 gcc 错误?

P.S:- 我通过python3 -m venv myenv 安装了virtualenv

【问题讨论】:

  • 运行pip install --update pip
  • @Anwarvic 更新后 pip 。错误减少了,现在的错误是Requirement already satisfied: joblib in ./myenv/lib/python3.5/site-packages (from nltk) (0.15.1) ERROR: Package 'joblib' requires a different Python: 3.5.2 not in '>=3.6' 我正在使用python 3.5.2
  • @Anwarvic 你能解释一下 gcc 错误以及为什么升级 pip 解决了它
  • 我已经在下面解释了这个问题。

标签: python linux pip nltk gcc-warning


【解决方案1】:

我认为解决方案在于错误,因为它指出:

Command "/home/pavan/Desktop/chatbot/myenv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-s1j858so/regex/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-5loncafz-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/pavan/Desktop/chatbot/myenv/include/site/python3.5/regex" failed with error code 1 in /tmp/pip-build-s1j858so/regex/
You are using pip version 8.1.1, however version 20.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

所以,您使用的是8.1.1 的 pip 版本,它太旧了,因为当前版本是 20.1.1。因此,使用以下命令升级pip 将解决您的问题:

pip install --upgrade pip

【讨论】:

  • 我在使用不太老的pip 19 时遇到了同样的错误。
  • 这个问题应该是在早期版本中处理的
  • 好的,但问题尚未解决。请参阅我上面的错误评论
  • 作为错误状态,你有 python 3.5 并且要使用 joblib 你至少需要 python 3.6
  • 我不能在 3.5 中使用 nltk 吗? .我在更新到 python 3.6 时遇到了非常糟糕的情况
猜你喜欢
  • 2017-09-12
  • 2018-08-05
  • 2015-03-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多