Ansible psutil无法在python3 virtualenv内部进行pip安装:致命错误:Python.h:没有这样的文件或目录

Ansible psutil无法在python3 virtualenv内部进行pip安装:致命错误:Python.h:没有这样的文件或目录,ansible,virtualenv,ansible-tower,Ansible,Virtualenv,Ansible Tower,我创建了一个python3virtualenv,以便在Python3中运行塔作业,因为python2是EOL。我按照此处的说明进行了操作:但psutil安装失败,出现以下错误: python36/root/usr/include/python3.6m -c psutil/_psutil_common.c -o build/temp.linux-x86_64-3.6/psutil/_psutil_common.o psutil/_psutil_common.c:9:20: fatal er

我创建了一个python3virtualenv,以便在Python3中运行塔作业,因为python2是EOL。我按照此处的说明进行了操作:但psutil安装失败,出现以下错误:

python36/root/usr/include/python3.6m -c psutil/_psutil_common.c -o build/temp.linux-x86_64-3.6/psutil/_psutil_common.o
    psutil/_psutil_common.c:9:20: fatal error: Python.h: No such file or directory
     #include <Python.h>
                        ^
    compilation terminated.
    error: command 'gcc' failed with exit status 1
其他人建议安装python3-devel,但已经安装了

环境:

  • CentOS 7.7
  • 蟒蛇3-devel-3.6.8
  • Python 3.6.8
  • pip3 9.0.3
  • Ansible塔3.5.0
更完整的错误跟踪:

# pip install psutil
Collecting psutil
  Downloading <CENSORED>/psutil-5.7.0.tar.gz (449kB)
    100% |████████████████████████████████| 450kB 52.5MB/s
Building wheels for collected packages: psutil
  Running setup.py bdist_wheel for psutil ... error

...

    gcc -pthread -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -I/opt/rh/rh-python36/root/usr/include -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPSUTIL_POSIX=1 -DPSUTIL_SIZEOF_PID_T=4 -DPSUTIL_VERSION=570 -DPSUTIL_LINUX=1 -I/opt/rh/rh-python36/root/usr/include/python3.6m -c psutil/_psutil_common.c -o build/temp.linux-x86_64-3.6/psutil/_psutil_common.o
    psutil/_psutil_common.c:9:20: fatal error: Python.h: No such file or directory
     #include <Python.h>
                        ^
    compilation terminated.
    error: command 'gcc' failed with exit status 1

    ----------------------------------------
Command "/opt/my-envs/custom-venv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-gv49hqf0/psutil/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-4oyv7j_1-record/install-record.txt --single-version-externally-managed --compile --install-headers /opt/my-envs/custom-venv/include/site/python3.6/psutil" failed with error code 1 in /tmp/pip-build-gv49hqf0/psutil/
#pip安装psutil
收集psutil
下载/psutil-5.7.0.tar.gz(449kB)
100% |████████████████████████████████| 450kB 52.5MB/s
为收集的包构建控制盘:psutil
正在为psutil运行setup.py bdist\u控制盘。。。错误
...
gcc-pthread-Wno unused result-Wsign compare-DDYNAMIC_ANNOTATIONS_ENABLED=1-DNDEBUG-O2-g-pipe-Wall-Wp-D_-FORTIFY_SOURCE=2-feexceptions-fstack protector-strong-param=ssp buffer size=4-grecord gcc switches-m64-mtune=generic-D_GNU_-SOURCE-fPIC-frapv-I/opt/rh/rh/rh-python36/root/usr/include-O2-g-pipe-Wall-Wp,-D_-FORTIFY_-SOURCE=2-feexceptions-fstack-protector-strong-param=ssp buffer size=4-grecord gcc-switches-m64-mtune=generic-D_-GNU-SOURCE-fPIC-fwrapv-fPIC-DPSUTIL_-POSIX=1-DPSUTIL-SIZEOF_-PID_-T=4-DPSUTIL-VERSION=570-DPSUTIL-LINUX=1-I/opt/rh/rh-python36/root/usr/include/python3.6m-c psutil-common.c-cbuild/temp.linux-x86\u 64-3.6/psutil/\u psutil\u common.o
psutil/_psutil_common.c:9:20:致命错误:Python.h:没有这样的文件或目录
#包括
^
编译终止。
错误:命令“gcc”失败,退出状态为1
----------------------------------------
命令“/opt/myenvs/customvenv/bin/python3-u-c”导入setuptools,标记化__文件\ \='/tmp/pip-build-gv49hqf0/psutil/setup.py';f=getattr(标记化“打开”,打开)(_文件);code=f.read().replace('\r\n','\n');f、 close();exec(compile(code,_ufile,_u,'exec'))“安装--record/tmp/pip-4oyv7j_1-record/install-record.txt--外部管理的单一版本--编译--install headers/opt/my envs/custom venv/include/site/python3.6/psutil”失败,错误代码为1,出现在/tmp/pip-build-gv49hqf0/psutil中/

事实证明virtualenv命令是一个python2构造。Ansible Tower文档的建议是错误的:

改用Python3 venv模块:

sudo python3 -m venv /opt/my-envs/custom-venv
source /opt/my-envs/custom-venv/bin/activate 
sudo /opt/my-envs/custom-venv/bin/pip install psutil
这对我有用

yum install python3-devel
sudo python3 -m venv /opt/my-envs/custom-venv
source /opt/my-envs/custom-venv/bin/activate 
sudo /opt/my-envs/custom-venv/bin/pip install psutil
yum install python3-devel