6

I can't install python-ldap via pip, I get the following error:

$ sudo pip3.4 install python-ldap
Downloading/unpacking python-ldap
  Downloading python-ldap-2.4.19.tar.gz (138kB): 138kB downloaded
  Running setup.py (path:/tmp/pip_build_root/python-ldap/setup.py) egg_info for package python-ldap
    Traceback (most recent call last):
      File "<string>", line 17, in <module>
      File "/tmp/pip_build_root/python-ldap/setup.py", line 53
        print name + ': ' + cfg.get('_ldap', name)
                 ^
    SyntaxError: invalid syntax
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 17, in <module>

  File "/tmp/pip_build_root/python-ldap/setup.py", line 53

    print name + ': ' + cfg.get('_ldap', name)

             ^

SyntaxError: invalid syntax

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_root/python-ldap
Storing debug log for failure in /home/nima/.pip/pip.log

Any ideas how to resolve this?

Nima
  • 6,383
  • 7
  • 46
  • 68

3 Answers3

9

It seems that your python-ldap is implemented in Python-2.X but you're using Python-3.X (Print Is A Function in python 3). Therefore, you need to install a newer version of this library that supports Python-3.X or install the library in python-2.X which is not recommended.

You can install the proper version for Python-3.X though using following command:

# if pip3 is the default pip alias for python-3
pip3 install python3-ldap

# otherwise 
pip install python3-ldap

Also here is the link of PiPy package for further information. https://pypi.python.org/pypi/python3-ldap/0.9.8.4/

Mazdak
  • 105,000
  • 18
  • 159
  • 188
  • Yea that's what I'm confused about because the library uses python3 to build via sources. (http://pyldap.readthedocs.org/en/latest/install.html) and on github it's said to only support python >= 3.3. I guess I will just build it from sources instead. – Nima Apr 11 '15 at 21:19
  • @Nima it appears that `python-ldap` (which you tried to install with `pip`) and `PyLDAP` (the RTD and Github project you mentioned) are two entirely separate entities, hence the confusion. The package you want, `PyLDAP`, is not available for installation via `pip`/PyPI. – MattDMo Apr 11 '15 at 21:53
  • @MattDMo hah you are correct, I messed up the two :D – Nima Apr 11 '15 at 23:13
  • @Kasramvd I had an application running on python 2.7 which was using python-ldap . Now since we are upgrading to python 3.4 the module will ofcourse not work as you have mentioned. But will the methods previously implemented work after setting up python3-ldap. Huge version change problem – Tara Prasad Gurung Nov 07 '17 at 07:45
  • 1
    @TaraPrasadGurung It depends on the way that you're implemented those methods. If they don't have any conflict with Python-3.X it'll definitely work otherwise you might want to use libraries that automatically do that for you or at least enhance the process of converting, like docs.python.org/3.0/library/2to3.html – Mazdak Nov 07 '17 at 08:03
  • @Kasramvd yes the upgrade is really a pain. So if I guess if I have not used anything that will make a conflict for example print usage and others than it's going to work fine. thanks may be I will try to fix that way first. btw previously i was using `import ldap` so it must be now `import ldap3` I hope. Thanks alot – Tara Prasad Gurung Nov 07 '17 at 08:12
  • @Kasramvd I tried to make it work this way (1). installed ldap3 (2) imported ldap3 .(3) Replaced every instance of ldap with ldap3 ( RESULT )But that didn't solve the problem ,the problem is `AttributeError: module 'ldap3' has no attribute 'set_option'` some of the methods are not available for ldap3. Now I may need to find the new methods and replace them – Tara Prasad Gurung Nov 07 '17 at 09:58
  • @TaraPrasadGurung Yes, you should look for the equivalent method. You can google the error first it there wasn't any answer you can ask your question in SO. – Mazdak Nov 07 '17 at 10:41
4

You can install python-ldap which is implemented for python3

pip install python3-ldap
Ravi garg
  • 41
  • 3
0

Install winlapsearch

git clone https://github.com/ropnop/windapsearch.git
apt-get install python3-ldap
./windapsearch.py
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
deepak L
  • 1
  • 1
  • Please don't just recommend a library without any information about what the library is or how, specifically, it can be used to solve this specific problem. [Learn more](https://meta.stackoverflow.com/questions/251602/recommending-off-site-resources-when-questions-dont-ask-for-it/251605#251605). – Jeremy Caney Jun 02 '23 at 00:28