python "ImportError: cannot import name urandom"
Question: Somehow my python is broken and emits the error:

    
    
    jseidel@EDP15:/etc/default$ python -c 'import random'
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/usr/lib/python2.6/random.py", line 47, in <module>
        from os import urandom as _urandom
    ImportError: cannot import name urandom
    

This is NOT the virtualenv error that is so commonly documented here and
elsewhere: I don't use python directly, I have never setup a virtualenv
explicitly, and there is no virtualenv directory or python script that I can
find anywhere on my system.

I'm running Kubuntu 10.04 and until just recently my KPackageKit worked just
fine and handled updates with no problem. Now it shows nothing... maybe
because of this python error, maybe because of something else.

How do I go about finding the error and fixing python?


Answer: As suggested by @Armin Rigo, this worked for me:

1) Add a `print 42` at the end of the /usr/lib/python2.6/os.py file.

2) If you see "42", then that is the correct os.py file and the urandom module
is not include. Add the statement to include urandom (you can find a sample
from another os.py file). This was what worked for me.

3) If you don't see "42", then that's not the os.py file that you're using.
Find the random.py file that is crashing and insert `import os; print
os.__file__` to get more information about the failure.

