changing virtualenv folder on windows
Asked Answered
H

3

6

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

Horodko answered 28/5, 2013 at 7:32 Comment(5)
Did you change your python version or platform?Illa
Can you add the printout of python > import sys > sys.path?Illa
yes, the new system has a newer version of python (I think, not sure).adding the system python sys.path into the questionHorodko
is this the sys.path under your virtualenv?Illa
@Illa no, I can't get the sys path straight from python in the virtualenv since I can't get the python interpreter to run fron the env. But I'll post PYTHONPATHHorodko
I
1

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.

Illa answered 28/5, 2013 at 19:55 Comment(3)
hmm. I know I can reinstall a virtualenv, and I do have a requirement.txt from a pip freeze. but I'm not happy with this solution. if nothing else pops up, I'll just recheckout the repo, and reinstall itHorodko
You can try copying Lib and exe files in Scripts from a fresh virtualenv, but it's the same :-)Illa
I suspect copying would make it worse, currently I'm trying your suggestion of a fresh virtualenv with a reinstall of packages, hold your fingers for me.Horodko
S
22

Correcting python directory path in ENV_FOLDER\Lib\orig-prefix.txt helped me

Salvadorsalvadore answered 27/12, 2014 at 13:40 Comment(2)
This was my issue when moving from computer to computerVarhol
Worked for me too. I had reinstalled Python (Anaconda) into different directory.Obfuscate
I
1

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.

Illa answered 28/5, 2013 at 19:55 Comment(3)
hmm. I know I can reinstall a virtualenv, and I do have a requirement.txt from a pip freeze. but I'm not happy with this solution. if nothing else pops up, I'll just recheckout the repo, and reinstall itHorodko
You can try copying Lib and exe files in Scripts from a fresh virtualenv, but it's the same :-)Illa
I suspect copying would make it worse, currently I'm trying your suggestion of a fresh virtualenv with a reinstall of packages, hold your fingers for me.Horodko
C
0

I installed both py2 and py3 on my windows 10. And got this error by create virtualenv by using virtualenv xxx directly. After purging folder xxx and reinstalling with virtualenv -p TARGET_PY_EXE xxx everything works smoothly. Hope this will help multiple python windows users. By the way, I simply create env variables as PY2 and PY3 instead of adding absolute paths into PATH.

Chicory answered 27/11, 2017 at 22:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.