python - Python 2.7 pip install 失败缺少 pyconfig.h,可能安装的源分发错误?
问题描述
我正在尝试升级到 Python 2.7 的最高版本作为移植到 Python 3 的起始基础。
在 RHEL 上,我已经成功构建了源代码并创建了虚拟环境。但是在安装 PIP 包时会遇到错误,说 gcc 缺少包含的 pyconfig.h 文件。该错误发生在安装多个包时,下面以 greenlet==0.4.9 为例。
我高度怀疑这是由于我安装 Python 的方式:
错误消息说
gcc
包括目录-I/data/EBC/test-2.7.16/venv/include/python2.7
,我不确定这是否与问题有关。--prefix
安装时,我通过 command更改了默认值./configure --enable-optimizations --with-ensurepip=install --prefix=/data/python/python-2.7.16/
。然后我打电话make altinstall
。我再次测试而不
--prefix
使用默认值,然后make install
将二进制文件安装到默认路径。这次pip install
工作正常。
不熟悉源安装,所以不确定我是否做错了什么。请指出。
如果有兴趣,下面更详细的细节:
(venv) [ebackenduser@setsv test-2.7.16]$ pip install greenlet==0.4.9
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Collecting greenlet==0.4.9
Using cached greenlet-0.4.9.tar.gz (54 kB)
Building wheels for collected packages: greenlet
Building wheel for greenlet (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /data/EBC/test-2.7.16/venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-mKgh3S/greenlet/setup.py'"'"'; __file__='"'"'/tmp/pip-install-mKgh3S/greenlet/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-6zrQ58
cwd: /tmp/pip-install-mKgh3S/greenlet/
Complete output (14 lines):
running bdist_wheel
running build
running build_ext
building 'greenlet' extension
creating build
creating build/temp.linux-x86_64-2.7
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/data/EBC/test-2.7.16/venv/include/python2.7 -c greenlet.c -o build/temp.linux-x86_64-2.7/greenlet.o
In file included from greenlet.h:8:0,
from greenlet.c:5:
/data/EBC/test-2.7.16/venv/include/python2.7/Python.h:8:22: fatal error: pyconfig.h: No such file or directory
#include "pyconfig.h"
^
compilation terminated.
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Failed building wheel for greenlet
Running setup.py clean for greenlet
Failed to build greenlet
Installing collected packages: greenlet
Running setup.py install for greenlet ... error
ERROR: Command errored out with exit status 1:
command: /data/EBC/test-2.7.16/venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-mKgh3S/greenlet/setup.py'"'"'; __file__='"'"'/tmp/pip-install-mKgh3S/greenlet/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-zbXvb7/install-record.txt --single-version-externally-managed --compile --install-headers /data/EBC/test-2.7.16/venv/include/site/python2.7/greenlet
cwd: /tmp/pip-install-mKgh3S/greenlet/
Complete output (14 lines):
running install
running build
running build_ext
building 'greenlet' extension
creating build
creating build/temp.linux-x86_64-2.7
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/data/EBC/test-2.7.16/venv/include/python2.7 -c greenlet.c -o build/temp.linux-x86_64-2.7/greenlet.o
In file included from greenlet.h:8:0,
from greenlet.c:5:
/data/EBC/test-2.7.16/venv/include/python2.7/Python.h:8:22: fatal error: pyconfig.h: No such file or directory
#include "pyconfig.h"
^
compilation terminated.
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /data/EBC/test-2.7.16/venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-mKgh3S/greenlet/setup.py'"'"'; __file__='"'"'/tmp/pip-install-mKgh3S/greenlet/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-zbXvb7/install-record.txt --single-version-externally-managed --compile --install-headers /data/EBC/test-2.7.16/venv/include/site/python2.7/greenlet Check the logs for full command output.
(venv) [ebackenduser@setsv test-2.7.16]$
我用 2.7.5 和 2.7.16 的源代码分发进行了测试,两者都有相同的错误。在同一台主机上,我有一个 Python 的 RPM 安装(版本 2.7.5),并且在 pip install 中可以正常工作。所以这个问题只发生在 Python 的源代码安装中。
我在下面附上我的源代码分发安装步骤,供您参考。
./configure --enable-optimizations --with-ensurepip=install --prefix=/data/python/python-2.7.16/
make altinstall
./python -m pip install --no-cache-dir virtualenv --verbose
解决方案
您必须安装python-devel
包,其中包含编译各种 Python 包所需的头文件
$ yum install python-devel
推荐阅读
- python - 自动生成 Click 命令的所有帮助文档
- excel - Excel SUMIFS - 通过动态更改列定义 sum_range
- ajax - 如何在没有页面重定向的情况下单击将项目添加到购物车时修复添加到购物车按钮
- javascript - 将数字转换为字符串时找不到id
- java - 有没有办法在 Eclipse 中将 Java 类传递给新文件?
- typescript - 只有一些泛型的打字稿推断?
- performance - 如何设计工作流程
- makefile - Makefile 中缺少依赖项
- oracle - 我如何在 Pivot 的 IN 子句中传递 select sql
- json - 从 JSON API 显示 MapView 标记