psutil не может установить pip внутри python3 virtualenv: фатальная ошибка: Python .h: такого файла или каталога нет - PullRequest
0 голосов
/ 27 февраля 2020

Я создал Python3 virtualenv для запуска заданий Tower в python3 теперь, когда python2 - это EOL. Я следовал инструкциям здесь: 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

Вот как я создал свой virtualenv:

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
  • python3 -devel-3.6.8
  • Python 3.6.8
  • pip3 9.0.3
  • Ansible Tower 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/

1 Ответ

0 голосов
/ 27 февраля 2020

Оказывается, команда 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
...