简体   繁体   English

python“ImportError:无法导入名称urandom”

[英]python “ImportError: cannot import name urandom”

Somehow my python is broken and emits the error: 不知何故,我的python被破坏并发出错误:

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. 这不是在这里和其他地方经常记录的virtualenv错误:我没有直接使用python,我从未明确地设置virtualenv,并且没有我可以在我的系统上找到的virtualenv目录或python脚本。

I'm running Kubuntu 10.04 and until just recently my KPackageKit worked just fine and handled updates with no problem. 我正在运行Kubuntu 10.04,直到最近我的KPackageKit工作得很好并处理更新没有问题。 Now it shows nothing... maybe because of this python error, maybe because of something else. 现在它没有显示任何内容......也许是因为这个python错误,可能是因为其他原因。

How do I go about finding the error and fixing python? 我如何找到错误并修复python?

As suggested by @Armin Rigo, this worked for me: 正如@Armin Rigo所说,这对我有用:

1) Add a print 42 at the end of the /usr/lib/python2.6/os.py file. 1)在/usr/lib/python2.6/os.py文件的末尾添加一个print 42

2) If you see "42", then that is the correct os.py file and the urandom module is not include. 2)如果看到“42”,那么这是正确的os.py文件,并且不包括urandom模块。 Add the statement to include urandom (you can find a sample from another os.py file). 添加语句以包含urandom(您可以从另一个os.py文件中找到示例)。 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. 3)如果您没有看到“42”,那么这不是您正在使用的os.py文件。 Find the random.py file that is crashing and insert import os; print os.__file__ 找到崩溃的random.py文件并插入import os; print os.__file__ import os; print os.__file__ to get more information about the failure. import os; print os.__file__获取有关失败的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM