Ubuntu

import random fails because _urandom is unavailable

Reported by Brendan Cully on 2012-04-27
72
This bug affects 15 people
Affects Status Importance Assigned to Milestone
python-defaults (Ubuntu)
Undecided
Unassigned

Bug Description

To reproduce:

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

ProblemType: Bug
DistroRelease: Ubuntu 12.04
Package: python-minimal 2.7.3-0ubuntu2
ProcVersionSignature: Ubuntu 3.2.0-23.36-generic 3.2.14
Uname: Linux 3.2.0-23-generic x86_64
ApportVersion: 2.0.1-0ubuntu6
Architecture: amd64
Date: Fri Apr 27 09:02:38 2012
InstallationMedia: Ubuntu 10.10 "Maverick Meerkat" - Release amd64 (20101007)
ProcEnviron:
 TERM=xterm
 PATH=(custom, user)
 LANG=en_CA.UTF-8
 SHELL=/bin/zsh
SourcePackage: python-defaults
UpgradeStatus: Upgraded to precise on 2012-04-26 (0 days ago)

Brendan Cully (bcully) wrote :
Brendan Cully (bcully) wrote :

Sorry, I've just discovered this was a result of my python being a virtualenv python. There may still be a bug here, but it's not against python-minimal.

Changed in python-defaults (Ubuntu):
status: New → Invalid
Ana Nelson (ananelson) wrote :

I found this same error after upgrading to precise pangolin and activating my virtualenv. I was able to work around it by creating a fresh virtualenv which worked as expected, I just had to reinstall all python libs into the new virtualenv.

Error messages I saw:

When trying to run nosetests:

  File "/usr/lib/python2.7/multiprocessing/process.py", line 309, in __init__
    self._authkey = AuthenticationString(os.urandom(32))
AttributeError: 'module' object has no attribute 'urandom'

When trying to run pip:

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

Joe Jasinski (joe-jasinski) wrote :

Thanks for the info about rebuilding the virtualenv. Is there any way to get around the error without remaking each virtualenv? I have a few dozen of them and would hate to have to rebuild all of them unless absolutely necessary....

Hi, Joe.

I just ran virtualenv over the same installation and it worked:

$ virtualenv ~/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..............................................................................................................................................................................................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 them in the same dir, I just ran:

$ ls | xargs -I{} virtualenv {}

Joe Jasinski (joe-jasinski) wrote :

Thank you very much Victor, I'll give that a shot.

Joe Jasinski (joe-jasinski) wrote :

Seems to have worked. Thank you Adam.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Duplicates of this bug

Other bug subscribers