Python ImportError自Ubuntu 12.04升级以来不能导入urandom

时间:2021-06-16 09:13:40

Upgraded Ubuntu to Precise Pangolin (12.04), and Python's Random is now broken... I suspect other things might be broken too. How do I fix Python?

升级的Ubuntu到精确的穿山甲(12.04),而Python的随机现在被打破…我怀疑其他东西也可能被破坏。如何修复Python?

    File "/usr/lib/python2.7/random.py", line 47, in <module>
    from os import urandom as _urandom
ImportError: cannot import name urandom

Alas, poor Python! I knew him, Random, a module of infinite jest, of most probable chaos. He hath bore me on his randint() a thousand times, and now how abhorr'd in my workspace it is! My Exception Handler rises at it.

唉,可怜的Python !我认识他,兰登,他是一个无穷无尽的玩笑的模子,是最可能的混乱。他在他的兰丁()上烦了我一千次,现在在我的工作空间里是多么令人厌恶啊!我的异常处理程序站了起来。

edit Running in virtualenv

编辑virtualenv中运行

5 个解决方案

#1


45  

Is this your problem?

这是你的问题吗?

https://bugs.launchpad.net/ubuntu/+source/python-defaults/+bug/989856

https://bugs.launchpad.net/ubuntu/ +源/ python-defaults / +错误/ 989856

Seems to be caused by running it in a virtual environment, and there is a work around.

似乎是由在虚拟环境中运行它引起的,并且有一个工作。

BTW this was the top result in google.

顺便说一下,这是谷歌的最高结果。

#2


36  

I had the same problem when upgrading to 12.10, and when upgrading to 16.04 (In the 16.04, the message was no module named datetime.)

在升级到12.10时,我遇到了同样的问题,升级到16.04时(在16.04中,消息是没有名为datetime的模块)。

To solve it just ran virtualenv over the same installation and it worked. Give it the --no-site-packages flag to preserve your modules:

要解决这个问题,只需在相同的安装上运行virtualenv,就可以了。给它—无站点包标志来保存您的模块:

$ virtualenv --no-site-packages ~/lib/virtualenv/netunong
Overwriting /home/adam/lib/virtualenv/netunong/lib/python2.7/site.py with new content
New python executable in /home/adam/lib/virtualenv/netunong/bin/python
Installing distribute.....<skippping dots, of course>.......done.
Installing pip................done.
Overwriting /home/adam/lib/virtualenv/netunong/bin/activate with new content
Overwriting /home/adam/lib/virtualenv/netunong/bin/activate_this.py with new content

Since I have all of my virtualenvs in the same dir, I just ran:

因为我所有的艺术大师都在同一个目录中,所以我就跑了:

$ ls | xargs -I{} virtualenv  --no-site-packages {}

#3


7  

I was getting this same error and fixed it by just re-running virtualenv (e.g., virtualenv --no-site-packages ~/venv/myvirtualenv/).

我得到了同样的错误,通过重新运行virtualenv(例如,virtualenv—无站点包~/venv/myvirtualenv/)来修复它。

#4


1  

Another solution is to remove pip if you installed it with apt-get use wget to fetch it

另一个解决方案是删除pip,如果您安装了apt-get使用wget来获取它

wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py

and then run

然后运行

python get-pip.py or sudo python get-pip.py if you're not logged in with root.

python get-pip。py或sudo python get-pip。如果没有使用root登录,则使用py。

This worked for me.

这为我工作。

#5


0  

Okay, maybe it is just not configured? Check this site, and look at the Configuring section.

好吧,也许只是没有配置?检查这个站点,并查看配置部分。

#1


45  

Is this your problem?

这是你的问题吗?

https://bugs.launchpad.net/ubuntu/+source/python-defaults/+bug/989856

https://bugs.launchpad.net/ubuntu/ +源/ python-defaults / +错误/ 989856

Seems to be caused by running it in a virtual environment, and there is a work around.

似乎是由在虚拟环境中运行它引起的,并且有一个工作。

BTW this was the top result in google.

顺便说一下,这是谷歌的最高结果。

#2


36  

I had the same problem when upgrading to 12.10, and when upgrading to 16.04 (In the 16.04, the message was no module named datetime.)

在升级到12.10时,我遇到了同样的问题,升级到16.04时(在16.04中,消息是没有名为datetime的模块)。

To solve it just ran virtualenv over the same installation and it worked. Give it the --no-site-packages flag to preserve your modules:

要解决这个问题,只需在相同的安装上运行virtualenv,就可以了。给它—无站点包标志来保存您的模块:

$ virtualenv --no-site-packages ~/lib/virtualenv/netunong
Overwriting /home/adam/lib/virtualenv/netunong/lib/python2.7/site.py with new content
New python executable in /home/adam/lib/virtualenv/netunong/bin/python
Installing distribute.....<skippping dots, of course>.......done.
Installing pip................done.
Overwriting /home/adam/lib/virtualenv/netunong/bin/activate with new content
Overwriting /home/adam/lib/virtualenv/netunong/bin/activate_this.py with new content

Since I have all of my virtualenvs in the same dir, I just ran:

因为我所有的艺术大师都在同一个目录中,所以我就跑了:

$ ls | xargs -I{} virtualenv  --no-site-packages {}

#3


7  

I was getting this same error and fixed it by just re-running virtualenv (e.g., virtualenv --no-site-packages ~/venv/myvirtualenv/).

我得到了同样的错误,通过重新运行virtualenv(例如,virtualenv—无站点包~/venv/myvirtualenv/)来修复它。

#4


1  

Another solution is to remove pip if you installed it with apt-get use wget to fetch it

另一个解决方案是删除pip,如果您安装了apt-get使用wget来获取它

wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py

and then run

然后运行

python get-pip.py or sudo python get-pip.py if you're not logged in with root.

python get-pip。py或sudo python get-pip。如果没有使用root登录,则使用py。

This worked for me.

这为我工作。

#5


0  

Okay, maybe it is just not configured? Check this site, and look at the Configuring section.

好吧,也许只是没有配置?检查这个站点,并查看配置部分。