Created
December 8, 2016 03:15
-
-
Save autosquid/847c8af594570a2797af0ba1b2017452 to your computer and use it in GitHub Desktop.
update python in virtualenv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Updated: I changed the answer 5 months after I originally answered. The following method is more convenient and robust. | |
| Side effect: it also fixes the Symbol not found: _SSLv2_method exception when you do import ssl in a virtual environment after upgrading Python to v2.7.8. | |
| Notice: Currently, this is for Python 2.7.x only. | |
| If you're using Homebrew Python on OS X, first deactivate all virtualenv, then upgrade Python: | |
| brew update && brew upgrade python | |
| Run the following commands (<EXISTING_ENV_PATH> is path of your virtual environment): | |
| rm <EXISTING_ENV_PATH>/bin/pip | |
| rm <EXISTING_ENV_PATH>/bin/pip2 | |
| rm <EXISTING_ENV_PATH>/bin/pip2.7 | |
| rm <EXISTING_ENV_PATH>/bin/python | |
| rm <EXISTING_ENV_PATH>/bin/python2 | |
| rm <EXISTING_ENV_PATH>/bin/python2.7 | |
| rm -r <EXISTING_ENV_PATH>/include/python2.7 | |
| rm <EXISTING_ENV_PATH>/lib/python2.7/* | |
| rm -r <EXISTING_ENV_PATH>/lib/python2.7/distutils | |
| rm <EXISTING_ENV_PATH>/lib/python2.7/site-packages/easy_install.* | |
| rm -r <EXISTING_ENV_PATH>/lib/python2.7/site-packages/pip | |
| rm -r <EXISTING_ENV_PATH>/lib/python2.7/site-packages/pip-*.dist-info | |
| rm -r <EXISTING_ENV_PATH>/lib/python2.7/site-packages/setuptools | |
| rm -r <EXISTING_ENV_PATH>/lib/python2.7/site-packages/setuptools-*.dist-info | |
| Finally, re-create your virtual environment: | |
| virtualenv <EXISTING_ENV_PATH> | |
| By doing so, old Python core files and standard libraries (plus setuptools and pip) are removed, while the custom libraries installed in site-packages are preserved and working, as soon as they are in pure Python. Binary libraries may or may not need to be reinstalled to function properly. | |
| This worked for me on 5 virtual environments with Django installed. | |
| BTW, if ./manage.py compilemessages is not working afterwards, try this: | |
| brew install gettext && brew link gettext --force | |
| shareeditflag | |
| edited Dec 11 '14 at 3:19 | |
| answered Jul 13 '14 at 15:36 | |
| Rockallite | |
| 1,7371418 | |
| The only file I had to delete was the bin/python file. – Koen. Sep 26 at 22:21 | |
| For some older version Python, deleting setuptools and pip is necessary. – Rockallite Sep 26 at 23:02 | |
| I also had to delete <EXISTING_ENV_PATH>/.Python as that broke the virtualenv creation. – Kiran Jonnalagadda Oct 19 at 11:16 | |
| add a comment |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment