【问题标题】:How to modify gcc command inside pip如何在 pip 中修改 gcc 命令
【发布时间】:2020-04-21 06:35:16
【问题描述】:

在使用 pip (pip install python-ldap) 安装 python-ldap 期间,我收到错误:

Modules/common.h:9:20: fatal error: Python.h: No such file or directory
 #include "Python.h"
                    ^
compilation terminated.
error: command 'gcc' failed with exit status 1

我在我的虚拟环境中执行此操作 (python -m venv)

我试图在这里找到我的问题的答案:

为了尝试修复错误而采取的步骤但没有:

yum install rh-python36-python-devel.x86_64

我还检查了 Python.h 文件是否在 pip 参数的 gcc 命令之一中:

    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 -DHAVE_SASL -DHAVE_TLS -DHAVE_LIBLDAP_R -DHAVE_LIBLDAP_R -DLDAPMODULE_VERSION=3.2.0 -DLDAPMODULE_AUTHOR=python-ldap project -DLDAPMODULE_LICENSE=Python style -IModules -I/me01/apps/onetick/apps/temp/venv2/include -I/opt/rh/rh-python36/root/include/python3.6m -c Modules/LDAPObject.c -o build/temp.linux-x86_64-3.6/Modules/LDAPObject.o

而且 Python.h 并不位于上述所有位置,它位于 /opt/rh/rh-python36/root/usr/include/python3.6m/Python.h 内。问题是:

如何修改pip执行的gcc命令?

PS 也试过了

 "pip command here" --global-option=build_ext --global-option="-l /path/to/libraries/"

PSS 我找到了解决方法:

在 venv/include 中复制库。

【问题讨论】:

    标签: python gcc pip


    【解决方案1】:

    由于没有人回答这里的问题是解决方案。 我不知道在 pip install 命令期间执行 gcc 的确切时间、原因和情况,但是在我们的 linux 系统中,我的配置中设置了 CC 变量到“gcc”可能是因为 yum install devtoolset-8。 当我将 CC 命令设置为低于 1 时,gcc 也知道在哪里寻找库:

    export CC="gcc -I/opt/rh/rh-python36/root/usr/include/python3.6m/"
    

    在此之后 pip install python-ldap 运行良好。

    知识:

    https://developers.redhat.com/HW/gcc-RHEL-7/

    https://gcc.gnu.org/onlinedocs/gfortran/Option-Summary.html#Option-Summary

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-11
      • 2016-09-03
      • 2011-06-05
      • 1970-01-01
      • 2021-09-29
      • 1970-01-01
      • 2014-06-09
      相关资源
      最近更新 更多