gcc 使用 pip 安装 psutil (及其依赖项) 时出错

gcc 使用 pip 安装 psutil (及其依赖项) 时出错

我正在尝试使用 pip 安装 Apache Airflow。在此过程中,它尝试安装 psutil,并出现 gcc 错误。如果我尝试单独安装 psutil,它仍然会出现相同的错误。

pip install psutil


Collecting psutil
  Using cached https://files.pythonhosted.org/packages/1c/ca/5b8c1fe032a458c2c4bcbe509d1401dca9dda35c7fc46b36bb81c2834740/psutil-5.6.3.tar.gz
Installing collected packages: psutil
  Running setup.py install for psutil ... error
    Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-4on5rz85/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-i327xkin-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.6
    creating build/lib.linux-x86_64-3.6/psutil
    copying psutil/__init__.py -> build/lib.linux-x86_64-3.6/psutil
    copying psutil/_common.py -> build/lib.linux-x86_64-3.6/psutil
    copying psutil/_compat.py -> build/lib.linux-x86_64-3.6/psutil
    copying psutil/_psaix.py -> build/lib.linux-x86_64-3.6/psutil
    copying psutil/_psbsd.py -> build/lib.linux-x86_64-3.6/psutil
    copying psutil/_pslinux.py -> build/lib.linux-x86_64-3.6/psutil
    copying psutil/_psosx.py -> build/lib.linux-x86_64-3.6/psutil
    copying psutil/_psposix.py -> build/lib.linux-x86_64-3.6/psutil
    copying psutil/_pssunos.py -> build/lib.linux-x86_64-3.6/psutil
    copying psutil/_pswindows.py -> build/lib.linux-x86_64-3.6/psutil
    creating build/lib.linux-x86_64-3.6/psutil/tests
    copying psutil/tests/__init__.py -> build/lib.linux-x86_64-3.6/psutil/tests
    copying psutil/tests/__main__.py -> build/lib.linux-x86_64-3.6/psutil/tests
    copying psutil/tests/runner.py -> build/lib.linux-x86_64-3.6/psutil/tests
    copying psutil/tests/test_aix.py -> build/lib.linux-x86_64-3.6/psutil/tests
    copying psutil/tests/test_bsd.py -> build/lib.linux-x86_64-3.6/psutil/tests
    copying psutil/tests/test_connections.py -> build/lib.linux-x86_64-3.6/psutil/tests
    copying psutil/tests/test_contracts.py -> build/lib.linux-x86_64-3.6/psutil/tests
    copying psutil/tests/test_linux.py -> build/lib.linux-x86_64-3.6/psutil/tests
    copying psutil/tests/test_memory_leaks.py -> build/lib.linux-x86_64-3.6/psutil/tests
    copying psutil/tests/test_misc.py -> build/lib.linux-x86_64-3.6/psutil/tests
    copying psutil/tests/test_osx.py -> build/lib.linux-x86_64-3.6/psutil/tests
    copying psutil/tests/test_posix.py -> build/lib.linux-x86_64-3.6/psutil/tests
    copying psutil/tests/test_process.py -> build/lib.linux-x86_64-3.6/psutil/tests
    copying psutil/tests/test_sunos.py -> build/lib.linux-x86_64-3.6/psutil/tests
    copying psutil/tests/test_system.py -> build/lib.linux-x86_64-3.6/psutil/tests
    copying psutil/tests/test_unicode.py -> build/lib.linux-x86_64-3.6/psutil/tests
    copying psutil/tests/test_windows.py -> build/lib.linux-x86_64-3.6/psutil/tests
    running build_ext
    building 'psutil._psutil_linux' extension
    creating build/temp.linux-x86_64-3.6
    creating build/temp.linux-x86_64-3.6/psutil
    gcc -pthread -Wno-unused-result -Wsign-compare -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 -fPIC -DPSUTIL_POSIX=1 -DPSUTIL_VERSION=563 -DPSUTIL_LINUX=1 -I/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 "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-4on5rz85/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-i327xkin-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-4on5rz85/psutil/

我知道它关于 psutil 说“没有这样的文件或目录”,但如果我尝试安装它,我似乎无法猜测如何获得该目录。

我已经尝试使用 pip、pip3 和 python3 -m pip,但收到相同的消息。

我已经安装了 python-devel 和 openssl-devel(根据网上的一些推荐)。

任何帮助都将不胜感激,谢谢。

规格:gcc 版本 4.8.5 20150623,Red Hat 7.7

答案1

谢谢@KnudLarsen寻求帮助。这就是我的窍门,以防有人遇到同样的问题。

我安装了 CentOS 存储库。我尝试从那里下载 python3-devel 包,但依赖项存在问题,特别是 python3 和 python3-libs,我拥有的版本是 python3-3.6.8-10.0.1 和 python3-libs-3.6.8-10.0.1,需要版本 python3-3.6.8-10 和 python3-libs-3.6.8-10。

因此,我删除了这些软件包(以及它们所依赖的软件包),并尝试再次安装它们(实际上,只需安装 python3-devel 就足够了)。它安装了正确的版本,然后安装 psutil 或 apache-airflow 的 pip 命令就可以正常工作了。

PD:我发现某个地方说我必须更新 gcc 版本才能使其工作。我不需要它,但如果我所做的对你(假设是读者)不起作用,请尝试这样做。

答案2

Oracle Enterprise 与原始的 Redhat RHEL 略有不同。(Oracle EL 是 Redhat 克隆。)

您可以从免费版本 =‘Redhat CentOS 7.7’中获取默认软件包:

http://mirror.centos.org/centos/7.7.1908/

相关内容