[Fixed]-ImportError: cannot import name "urandom"


You have to recreate your virtual environment.

My guess is that the following has happended:

  1. You created a virtualenv
  2. At some later point in time, the system’s Python installation was updated with the urandom security bugfix.
  3. Your virtualenv (created from a previous Python point release) does not work anymore (due to the issue you mention in your question)

The simplest fix is to delete your virtual environment and create a new one:

$ virtualenv VIRTUALENVDIR
$ . VIRTUALENVDIR/bin/activate

# then pip install any required packages, if your project has a requirements.txt file,
# this is simply:
$ pip install -r requirements.txt

# otherwise, you will have to install each package
$ pip install packagename
$ pip install packagename==version

Leave a comment