python “ImportError: cannot import name urandom”

Deadly 提交于 2020-01-03 22:57:12

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/13545030/python-importerror-cannot-import-name-urandom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!