[issue14444] Virtualenv not portable from Python 2.7.2 to 2.7.3 (os.urandom missing)
Jason R. Coombs
report at bugs.python.org
Thu Apr 12 23:34:38 CEST 2012
Jason R. Coombs <jaraco at jaraco.com> added the comment:
For posterity, here's the release notes that we had drafted on the pirate pad:
Note: This patch release of Python may have compatibility implications for environments utilizing the third-party virtualenv. For more detail see XXX.
[the note above is intended to be included as a line-item in the release notes, referencing the file below]
Upgrade issues with virtualenv
In order to enact a security fix in Python 2.6.8, 2.7.3, 3.1.5, and 3.2.3, the implementation of os.urandom was updated. The implementation of urandom was moved from the os module (Python stdlib) to the posix module (built in to the Python executable binary). As a result, when upgrading a host to one of these new Python versions, virtual environments created with earlier versions of Python will now be missing os.urandom. This issue only exists for Unix hosts.
This happens because the virtualenv bundles the older Python executable (which does not have an implementation of urandom), but then references the newer standard library (in which the os module also does not have an implementation of urandom).
In environments where this error occurs, the error is most likely exhibited as an AttributeError:
$ $ENV/bin/python -c "import os; os.urandom"
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute 'urandom'
The workaround is to remove the 'python' binary from $ENV/bin and re-run virtualenv for the required Python version or versions on that environment. For example:
$ rm $ENV/bin/python
$ virtualenv --python python2.7 $ENV
It's necessary to remove the main python binary because virtualenv will not replace it if it already exists. If the virtualenv contained multiple Python versions, run virtualenv on it again with each Python. If the --distribute flag was used in the initial creation of the virtualenv, use it again here.
Python tracker <report at bugs.python.org>
More information about the Python-bugs-list