Python3 venv: Can env directory be renamed?

不羁的心 提交于 2019-12-08 18:13:53

问题


I'm using Python 3.4 on Windows. I have created a virtual environment with

python c:\Python34\Tools\Scripts\pyvenv.py foo

Then activated it

foo\Scripts\activate.bat

And installed several libraries in it.

Question: Is it safe to rename the venv folder "foo" to "bar"? I.e. once i have renamed foo to bar, then activate it with

bar\Scripts\activate.bat

will it still work?

What could make problems are any environment variable settings and absolute paths.


回答1:


To be able to do that you should use virtualenv. From the docs:

Normally environments are tied to a specific path. That means that you cannot move an environment around or copy it to another computer. You can fix up an environment to make it relocatable with the command:

$ virtualenv --relocatable ENV

This will make some of the files created by setuptools or distribute use relative paths, and will change all the scripts to use activate_this.py instead of using the location of the Python interpreter to select the environment.

Note: you must run this after you've installed any packages into the environment. If you make an environment relocatable, then install a new package, you must run virtualenv --relocatable again.

But be aware:

The --relocatable option currently has a number of issues, and is not guaranteed to work in all circumstances. It is possible that the option will be deprecated in a future version of virtualenv.



来源:https://stackoverflow.com/questions/22946719/python3-venv-can-env-directory-be-renamed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!