致命错误:Python.h:没有从来源安装pip安装和python3的此类文件或目录

时间:2018-12-06 19:51:12

标签: python python-3.x pip

我以这种方式从源代码安装了python3和pip:

wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
tar xzf Python-3.7.0.tgz
cd Python-3.7.0
./configure --enable-optimizations
make altinstall

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py

运行命令时出现以下错误:pip install -r requirements.txt

x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c src/twisted/test/raiser.c -o build/temp.linux-x86_64-2.7/src/twisted/test/raiser.o
  src/twisted/test/raiser.c:4:20: fatal error: Python.h: No such file or directory
   #include "Python.h"
                    ^
  compilation terminated.
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-C0apcH/Twisted/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-kq7bc8/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-C0apcH/Twisted/
The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 1

我读到必须安装python3-dev,并且看到答案提示要使用apt-get install python3-dev。但是我没有用apt-get安装python3,所以我认为这种方法并不适用。我猜应该设置一个环境变量,但是我没有。

感谢您的帮助, 蒂埃里

0 个答案:

没有答案