[newbie] import fails first time, then works :-[

laotseu bdesth at nospam.free.fr
Fri Jun 21 16:36:01 EDT 2002


Peter Hansen wrote:
> laotseu wrote:
> 
>>Hi Everybody
>>
>>I've got this strange problem :
>>when importing modules that wrap external modules (like socket and
>>_socket etc), the first time, I get an ImportError
>>(no module named _[module]).
>>If i try a second time, it works ok ?-o
>>
>>Exemple :
>> >>> import socket
>>Traceback (most recent call last):
>>   File "<stdin>", line 1, in ?
>>   File "/usr/local/lib/python2.2/socket.py", line 41, in ?
>>     from _socket import *
>>ImportError: No module named _socket
>> >>> import socket
>> >>> socket
>><module 'socket' from '/usr/local/lib/python2.2/socket.pyc'>
> 

Hi Peter
Wow ! faster than lightnin !

> See recent postings in the archives for explanations about why this
> is actually _not_ working the second time, but only appears to.

Testing a little bit further, I discovered that fact...


> In this case, despite that you say the external modules are in the
> right place, there is probably something wrong with the _socket
> external module 

I guess not, I had the same problem with all external modules.

>or it cannot be found and that's the root cause
> of your trouble.

Well... I added '/usr/local/lib/lib-dynload' to my PYTHONPATH and 
'import' does not complain anymore. Everything seems just fine now. But 
that is puzzling me ! [being a python newbie,] I thought the 
'/lib-dynload/' directorie, that is in the '/lib/python<version>/' 
directories, was automagically searched for external modules. Was I wrong ?

Thanks anyway for your fast answser, and may the force be with you (and 
your favorite snake)

laotseu

> -Peter





More information about the Python-list mailing list