【发布时间】:2020-09-18 03:54:14
【问题描述】:
我正在尝试升级到 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的目录,我不确定这是否与问题有关。 -
安装时,我通过命令
./configure --enable-optimizations --with-ensurepip=install --prefix=/data/python/python-2.7.16/更改了默认--prefix。然后我打电话给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 2 吗?它不再受到官方支持。
-
我正在测试升级到 Python-3 的路径,并希望升级到 2.7 的最后一个版本作为起始基础。
标签: python python-2.7 pip redhat