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

Peter Hansen peter at engcorp.com
Fri Jun 21 09:38:45 EDT 2002


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'>

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

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 or it cannot be found and that's the root cause
of your trouble.

-Peter



More information about the Python-list mailing list