NBajanca
NBajanca

Reputation: 3730

Pyldap (to use Django Auth LDAP) install in a python3 virtualenv

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:

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.

Upvotes: 2

Views: 3177

Answers (2)

e4c5
e4c5

Reputation: 53774

you cannot install a package into a virtualenv using sudo. You must use sudo only to install the dependencies. For example

sudo apt-get install -y python-dev libldap2-dev libsasl2-dev libssl-dev

updated: 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

source myvirtualenv/bin/activate
pip3 install pyldap

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:

virtualenv -p python3 myvirtualenv

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:

sudo -i
source myvirtualenv/bin/activate
pip3 install pyldap

Upvotes: 3

Pancho Jay
Pancho Jay

Reputation: 500

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.

Upvotes: 0

Related Questions