How to rebuild virtualenvs after removing associated python interpreter
I have a number of django projects organized with the following directory structure using win7 (I am using GIT_BASH / mingw for my command line):
envs--r1--project1
--project2
--Include
--Library
--Scripts--python.exe
python275--
The idea is that different projects have a common environment and I can activate that environment from the root of each project using:
$ source ../Scripts/activate
I don't know exactly how this happened, but it turned out that the interpreter (listed above as python.exe) was somehow linked to the second python folder above.
I deleted the python275 folder (AAHH !!) without realizing its importance, resulting in:
Traceback (most recent call last): File "C:\envs\r1\lib\site.py", line 703, in main() File "C:\envs\r1\lib\site.py", line 692, in main aliasmbcs() File "C:\envs\r1\lib\site.py", line 515, in aliasmbcs import locale, codecs File "C:\envs\r1\lib\locale.py", line 19, in import functools ImportError: No module named functools
I reinstalled the correct python folder but the error persists. Can anyone advise me on how to rebuild virtualenvs so I can get back to how it was?
edit:
(r1)
/C/envs/r1/Scripts
$ import reload(functools)
sh: syntax error near unexpected token `('
(r1)
/C/envs/r1/Scripts
$ python.exe import reload(functools)
sh: syntax error near unexpected token `('
(r1)
/C/envs/r1/Scripts
$ python.exe reload functools
Traceback (most recent call last):
File "C:\envs\r1\lib\site.py", line 703, in <module>
main()
File "C:\envs\r1\lib\site.py", line 692, in main
aliasmbcs()
File "C:\envs\r1\lib\site.py", line 515, in aliasmbcs
import locale, codecs
File "C:\envs\r1\lib\locale.py", line 19, in <module>
import functools
ImportError: No module named functools
(r1)
/C/envs/r1/Scripts
$ reload(functools)
sh: syntax error near unexpected token `('
(r1)
/C/envs/r1/Scripts
$ python.exe reload(functools)
sh: syntax error near unexpected token `('
(r1)
/C/envs/r1/Scripts
$ python.exe test.py
Traceback (most recent call last):
File "f:\envs\r1\lib\site.py", line 703, in <module>
main()
File "f:\envs\r1\lib\site.py", line 692, in main
aliasmbcs()
File "f:\envs\r1\lib\site.py", line 515, in aliasmbcs
import locale, codecs
File "f:\envs\r1\lib\locale.py", line 19, in <module>
import functools
ImportError: No module named functools
source to share
I suggest reinstalling Python and virtualenv from scratch in your case, then re-creating the environment (s).
- Make sure you have a working installation of Python 2.7.5 installed on your system.
- Make sure you have it installed
pip
( view docs ). - Make sure to
pip
link to the Python installation above (check the outputpip -V
, it should contain the correct system-wide Python path). - Do a clean install of virtualenv with
pip install virtualenv
. - Create and activate an environment for your projects.
-
Reinstall in your new environment all the modules you installed in your old environment.
This can be tricky.
- If you have an updated file, for example
requirements.txt
with all the required packages, then you are all set (pip install -r requirements.txt
should do it). - If you do not have the listed requirements or they are not updated, then manually check which packages were installed in the old environment. To do this, you have to find a directory
site-packages
in your old virtualenv (should be underLibrary
maybe) and see what's there. Each non-system package that you recognize in the directorysite-packages
you install into a new environment (usually usingpip install
, but some packages may have custom instructions).
- If you have an updated file, for example
What did I do when this happened to me. I couldn't just rebuild the environment, so I did a reinstall for cleanliness.
source to share
Taken from another post. You can link virtualenv to python version.
You tell the Python interpreter to use with the -p or -python flag (for example --python = python2.5)
virtualenv -p /usr/bin/python2.6 <path/to/new/virtualenv/>
But it just works to create new environments. You will need to access your old virtualenv and execute:
pip freeze > requirements.txt
The requirements.txt file contains all applications installed in the old virtual environment and their respective versions. Now, from the new environment you created, run:
pip install -r requirements.txt
You must activate the virtual environment.
$ source /yourvirtualenvpath/bin/activate
$ pip freeze > /home/user/requirements.txt
$ deactivate
$ source /yourNEWvirtualenvpath/bin/activate
$ pip install -r /home/user/requirements.txt
source to share