views:

135

answers:

3

Hi guys,

I have an python error AttributeError: 'module' object has no attribute 'initialize' I am running Python 2.6.2 on Solaris 10 UNIX and recently installed the pythonldap 2.3.9. The script is very basic, only has these 2 lines. Can anyone tell me why?? Traceback error below.

#!/usr/local/bin/python

import ldap, sys

con = ldap.initialize('ldap://localhost')

Traceback (most recent call last): File "./myldap.py", line 5, in con = ldap.initialize('ldap://localhost') AttributeError: 'module' object has no attribute 'initialize'

Regards, Jenny

+2  A: 

Did you name a file in the current directory ldap.py that is shadowing the one that you want?

Mike Graham
Impressive. Speedy and helpful replies in just less than 2 minutes! Yes I did actually, I've renamed that file now and got another error. Traceback (most recent call last): File "./myldap.py", line 3, in <module> import ldap File "/usr/local/lib/python2.6/site-packages/ldap/__init__.py", line 22, in <module> from _ldap import *ImportError: ld.so.1: python: fatal: libsasl2.so.2: open failed: No such file or directory
jenny
Bingo! Inspect the installation of your ldap module. Seems it may be horked. And welcome to SO!!
jathanism
It looks like you are having trouble with the C module `ldap` needs to call. What operating system do you use? How did you install python-ldap?
Mike Graham
Actually I didn't install this myself but the engineer who did forwarded me these details. Solaris 10.Python and Pythonldap were installed from Sunfreeware site - both packages specifically for Solaris systems.Python:- SMCpython 2.6.2Pyhtonldap:- SMCpyldap 2.3.9
jenny
A: 

An easy way to tell if the ldap you're importing is the right one is to print ldap.__file__, which prints the full path to the module file (usually a '.pyc'). If it's not the one installed in the location you are expecting, this is your problem, as Mike Graham suggested.

jathanism
A: 

You can get that error if you're somehow picking up the "ldap.py" from sos/plugins/ instead of the ldap package itself. Make sure the "python-ldap" package is actually installed...

David Gelhar