Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: cannot import name "urandom" [closed]

I get this error when I try to runserver any of my projects while I'm running my virtual env (workon django1.2)

the error :

ImportError: cannot import name "urandom"

after researching the issue I found this:

Warning Python bugfix releases 2.6.8, 2.7.3, 3.1.5 and 3.2.3 include a change that will cause “import random” to fail with “cannot import name urandom” on any virtualenv created on a Unix host with an earlier release of Python 2.6/2.7/3.1/3.2, if the underlying system Python is upgraded. This is due to the fact that a virtualenv uses the system Python’s standard library but contains its own copy of the Python interpreter, so an upgrade to the system Python results in a mismatch between the version of the Python interpreter and the version of the standard library. It can be fixed by removing $ENV/bin/python and re-running virtualenv on the same target directory with the upgraded Python.

but running ENV/bin/python gives me :

bash: ENV/bin/python: No file or directory of this type

Where can I find my virtualen directory?

I understand very little about virtualenvs so please bear with me

thanks

like image 907
Armance Avatar asked Nov 02 '12 11:11

Armance


1 Answers

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:

$ rm -r VIRTUALENVDIR
$ 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
like image 134
codeape Avatar answered Oct 13 '22 18:10

codeape