I am trying to install pyldap to use it with django-auth-ldap but when doing:
pip install pyldap
I get:
In file included from Modules/LDAPObject.c:4:0:
Modules/common.h:10:20: fatal error: Python.h: No such file or directory
#include "Python.h"
^
compilation terminated.
error: command 'gcc' failed with exit status 1
Important
I am using Virtualenv, witch was created in python3:
virtualenv -p python3 myvirtualenv
And I have already installed the development packages (I am in CentOS, found in this answer) :
sudo yum install python-devel
sudo yum install openldap-devel
What I already tried
Create two new virtualenv:
- One with python 3.4 (using the command above) and the
pip install pyldap
doesn't work (with the error described above) - One with python 2.7 (using the command above without
-p python3
)and thepip install pyldap
works Install the package as root
sudo pip3 install pyldap
and it works but when I run in the django app in the virtualenv I get:import ldap ImportError: No module named 'ldap'
I pretend to use pyldap precisely because it supports python3 so I can't understand why this happens and how may I resolve it. If you can't answer this question directly but you know other library I may use for Active Directory authentication in Django please comment this question.
you cannot install a package into a
virtualenv
usingsudo
. You must use sudo only to install the dependencies. For exampleupdated: However if your system's default version of python is 2.x and your virtualenv is 3.x you will actually need to install python3-dev instead of python-dev.
For the actual installation
You are using pip3 here so make sure that your virtualenv has been setup to use python 3 with a command such as the following:
You can find out if what version is actually being used by entering the python shell.
As a foot note, if you really want to install a package as root:
You have to install python-dev package (assuming you use a Ubuntu/Debian Linux)
sudo apt-get install python-dev
Then try to install pyldap using pip3 without sudo.