Search code examples
pythonvirtualenvvirtualenv-commands

changing virtualenv folder on windows


after a computer fix my python projects dir (windows) changed (say from d: to f:). now all my virtualenvs are broken. after activating the env the project inside the virtualenv can't find the dependencies and the custom scripts (from the env\scripts folder)won't work

tried running:

virtualenv --relocateble ENV_NAME (with the env name ..)

like in this stackoverflow question and it outputted a lot of lines like:

Script agent\Scripts\deactivate.bat cannot be made relative

and my virtualenv is still broken.

when I manually changed activate.bat set VIRTUAL_ENV to the new path. some scripts work again. but the relocate scripts still doesn't run and most of the scripts are still broken

even running the python interpeter fails with:

Traceback (most recent call last):
  File "F:\Python27\learn\agent\agent\lib\site.py", line 677, in <module>
    main()
  File "F:\Python27\learn\agent\agent\lib\site.py", line 666, in main
    aliasmbcs()
  File "F:\Python27\learn\agent\agent\lib\site.py", line 506, in aliasmbcs
    import locale, codecs
  File "F:\Python27\learn\agent\agent\lib\locale.py", line 19, in <module>
    import functools
ImportError: No module named functools

is there any way to fix this? HELP

Update: I also changed manually the shebang python interpeter line in all scripts in ENV\Scripts. now all fail with the same python failure as above

Another Update: to @udi the system python path is:

['', 'C:\\dev\\Python27\\lib\\site-packages\\distribute-0.6.37-py2.7.egg', 'C:\\
dev\\Python27\\lib\\site-packages\\pip-1.3.1-py2.7.egg', 'C:\\dev\\Python27\\lib
\\site-packages\\numpy-1.7.1-py2.7-win32.egg', 'C:\\dev\\Python27\\lib\\site-pac
kages\\pandas-0.11.0-py2.7-win32.egg', 'C:\\dev\\Python27\\lib\\site-packages\\p
ytz-2013b-py2.7.egg', 'C:\\dev\\Python27\\lib\\site-packages\\python_dateutil-2.
1-py2.7.egg', 'C:\\dev\\Python27\\lib\\site-packages\\six-1.3.0-py2.7.egg', 'C:\
\dev\\Python27\\lib\\site-packages\\tornado-3.0.1-py2.7.egg', 'C:\\dev\\Python27
\\lib\\site-packages\\pyzmq-13.1.0-py2.7-win32.egg', 'C:\\dev\\Python27\\lib\\si
te-packages\\pygments-1.6-py2.7.egg', 'C:\\Windows\\system32\\python27.zip', 'C:
\\dev\\Python27\\DLLs', 'C:\\dev\\Python27\\lib', 'C:\\dev\\Python27\\lib\\plat-
win', 'C:\\dev\\Python27\\lib\\lib-tk', 'C:\\dev\\Python27', 'C:\\dev\\Python27\
\lib\\site-packages', 'C:\\dev\\Python27\\lib\\site-packages\\setuptools-0.6c11-
py2.7.egg-info']

since I can't run python from the virtualenv, I can't print the python path from there


Solution

  • Seems like your system and local environments create a mix of libraries and binaries from different versions of python.

    Chances are you would need to delete Lib, Scripts and Include and start again with virtualenv .. You might be able to save the site-packages folder, but if you have requirements.txt files, you should probably reinstall packages instead (see also: How do I install from a local cache with pip? ).

    Anyway, I believe you can create a script that does all this in one step.