views:

133

answers:

2

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

+4  A: 

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.

bobince
you are a genius, bobince
Baha
+1  A: 

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

>>> inspect.getabsfile(random)
J.F. Sebastian
thanks for the answer
Baha