user126284
user126284

Reputation:

help with python urllib2 import error

In my script, I've imported urrlib2 and the script was working fine. After reboot, I get the following error:

  File "demo.py", line 2, in <module>
    import urllib2
  File "/usr/lib/python2.6/urllib2.py", line 92, in <module>
    import httplib
  File "/usr/lib/python2.6/httplib.py", line 78, in <module>
    import mimetools
  File "/usr/lib/python2.6/mimetools.py", line 6, in <module>
    import tempfile
  File "/usr/lib/python2.6/tempfile.py", line 34, in <module>
    from random import Random as _Random
ImportError: cannot import name Random

And when I do import random separately, it works fine. Any ideas what might be wrong?

I'm using ubuntu 9.10 (up to date). thanks

Upvotes: 3

Views: 1413

Answers (2)

jfs
jfs

Reputation: 414069

Check that random is the stdlib's module and not some arbitrary module with the same name from sys.path.

>>> inspect.getabsfile(random)

Upvotes: 0

bobince
bobince

Reputation: 536319

The usual answer is that you've got a file called random.py in the current directory when the script is running. tempfile would be accidentally importing that random and not the stdlib random module.

Upvotes: 5

Related Questions