【发布时间】: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)
我试图在这里找到我的问题的答案:
- Python.h: No such file or directory when installing pandas
- How to install python3-devel on red hat 7
- fatal error: Python.h: No such file or directory
为了尝试修复错误而采取的步骤但没有:
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 中复制库。
【问题讨论】: