简体   繁体   English

在Windows上更改virtualenv文件夹

[英]changing virtualenv folder on windows

after a computer fix my python projects dir (windows) changed (say from d: to f:). 在计算机修复我的python项目dir(windows)改变后(比如从d:到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 激活env后,virtualenv中的项目无法找到依赖项,自定义脚本(来自env \\ scripts文件夹)将无法正常工作

tried running: 试过跑:

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

like in this stackoverflow question and it outputted a lot of lines like: 就像在这个stackoverflow问题中 ,它输出了很多行,如:

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

and my virtualenv is still broken. 我的virtualenv仍然破碎。

when I manually changed activate.bat set VIRTUAL_ENV to the new path. 当我手动更改activate.bat set VIRTUAL_ENV为新路径时。 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: 即使运行python interpeter也失败了:

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. 更新:我还在ENV \\ Scripts的所有脚本中手动更改了shebang python interpeter行。 now all fail with the same python failure as above 现在所有失败都与上面相同的python失败

Another Update: to @udi the system python path is: 另一个更新: @udi系统python路径是:

['', '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 因为我无法从virtualenv运行python,所以我无法从那里打印python路径

更正ENV_FOLDER\\Lib\\orig-prefix.txt python目录路径对我ENV_FOLDER\\Lib\\orig-prefix.txt帮助

Seems like your system and local environments create a mix of libraries and binaries from different versions of python. 好像您的系统和本地环境创建了来自不同版本的python的库和二进制文件的混合。

Chances are you would need to delete Lib , Scripts and Include and start again with virtualenv . 您可能需要删除LibScriptsInclude ,然后再使用virtualenv .重新开始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? ). 您可以保存site-packages文件夹,但如果您有requirements.txt文件,则应该重新安装软件包(另请参阅: 如何使用pip从本地缓存安装? )。

Anyway, I believe you can create a script that does all this in one step. 无论如何,我相信你可以创建一个脚本,一步完成所有这些。

I installed both py2 and py3 on my windows 10. And got this error by create virtualenv by using virtualenv xxx directly. 我在我的Windows 10上安装了py2和py3。并通过直接使用virtualenv xxx创建virtualenv来解决此错误。 After purging folder xxx and reinstalling with virtualenv -p TARGET_PY_EXE xxx everything works smoothly. 清除文件夹xxx并使用virtualenv -p TARGET_PY_EXE xxx重新安装后,一切顺利。 Hope this will help multiple python windows users. 希望这将有助于多个python windows用户。 By the way, I simply create env variables as PY2 and PY3 instead of adding absolute paths into PATH . 顺便说一句,我只是将env变量创建为PY2和PY3,而不是将绝对路径添加到PATH

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM