在Centos上的虚拟环境中安装python-ldap

时间:2017-09-07 08:56:12

标签: python centos7

我成功地在其他问题的帮助下成功安装了python-ldap。

[root@test myproj]# python test.py
[]

但是当在虚拟环境中时,我得到了这个"没有名为ldap的模块"

(venv)[root@test myproj]# python test.py
Traceback (most recent call last):
  File "test.py", line 1, in <module>
    import ldap
ImportError: No module named ldap

尝试安装 - 我收到很长的错误消息,但我认为重要的是

gcc -pthread -fno-strict-aliasing -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 -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 -DHAVE_SASL -DHAVE_TLS -DHAVE_LIBLDAP_R -DHAVE_LIBLDAP_R -DLDAPMODULE_VERSION=2.4.43 -IModules -I/usr/include -I/usr/include/sasl -I/usr/local/include -I/usr/local/include/sasl -I/usr/include/python2.7 -c Modules/LDAPObject.c -o build/temp.linux-x86_64-2.7/Modules/LDAPObject.o

unable to execute gcc: No such file or directory

error: command 'gcc' failed with exit status 1

尝试安装依赖项

(venv)[root@test socportal]# venv/bin/pip install python-dev
Downloading/unpacking python-dev
  Could not find any downloads that satisfy the requirement python-dev
Cleaning up...
No distributions at all found for python-dev
Storing complete log in /root/.pip/pip.log

我现在一直试图安装这个库超过5个小时,到处寻找。 迫切需要帮助。

1 个答案:

答案 0 :(得分:1)

从您的错误消息中,似乎没有安装gcc编译器,但需要编译您尝试安装的python包。

以root用户身份运行(或使用sudo),请使用

进行安装
yum install gcc

更进一步,其他方便的开发包存在于“开发工具”组中,包括gcc。以root用户身份运行(或使用sudo),您可以使用以下命令安装它:

 yum groupinstall “Development Tools”