我创建了一个Python3虚拟机,以便在Python3中运行Tower作业。我遵循了这里的说明:https://docs.ansible.com/ansible-tower/latest/html/upgrade-migration-guide/virtualenv.html但是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
这就是我创建虚拟现实的方式v:
sudo bash
mkdir /opt/my-envs/custom-venv
virtualenv -p /opt/rh/rh-python36/root/usr/bin/python3 /opt/my-envs/custom-venv/
source /opt/my-envs/custom-venv/bin/activate
pip install psutil ansible awscli boto boto3 botocore six urllib3 jmespath paramiko Jinja2
其他人建议安装python3-devel,但已经安装了。
环境:
- CentOS 7.7
- 蟒蛇3-发育3.6.8
- Python 3.6.8
- 管道3 9.0.3
- 安全塔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('rn', '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/
这对我有效。
yum install python3-devel
事实证明,virtualenv命令是一个python2构造。Ansible Tower文档的建议是错误的:https://docs.ansible.com/ansible-tower/latest/html/upgrade-migration-guide/virtualenv.html
sudo virtualenv -p /opt/rh/rh-python36/root/usr/bin/python3 /opt/my-envs/custom-venv
source /opt/my-envs/custom-venv/bin/activate
sudo /opt/my-envs/custom-venv/bin/pip install psutil
使用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