ImportError: cannot import name urandom

    import os, sys, imp, types, tempfile, optparse
  File "/usr/lib/python2.7/tempfile.py", line 34, in 
    from random import Random as _Random
  File "/usr/lib/python2.7/random.py", line 47, in 
    from os import urandom as _urandom
ImportError: cannot import name urandom

You’re using a virtualenv, you’re probably on Debian or Ubuntu, and you upgraded python through apt-get.

To fix it:

virtualenv /path/to/your/virtualenvironment

Tags:

2 Responses to “ImportError: cannot import name urandom”

  1. Alvaro F. Boirac Says:

    Hi,

    So how did you sort the error out? I’m getting the “cannot import name urandom” when starting django in a virtualenv after upgrading to ubuntu 12.04. Any clues? Thanks.

  2. Alvaro F. Boirac Says:

    Ok, solved. for the record, I just recreated the virtual env:
    $ virtualenv –no-site-packages ~/some-path/myvirtualenv
    $ source ~/some-path/myvirtualenv/bin/activate

    and it works. black magic. :-/

Leave a Reply

You must be logged in to post a comment.

Entries (RSS) and Comments (RSS).
Cluster host: li