-
venv
PEP405 proposes adding a new
venvmodule to the standard library which implements the creation of virtual environments.The
venvmodule provides support for creating lightweight “virtual environments” with their own site directories, optionally isolated from system site directories.Each virtual environment has its own Python binary (which matches the version of the binary that was used to create this environment) and can have its own independent set of installed Python packages in its site directories.
-
Virtual environment layout
A typical virtual environment layout on a POSIX system would be:
pyvenv.cfg bin/python3 bin/python bin/pysetup3 include/ lib/python3.3/site-packages/While on a Windows system:
pyvenv.cfg Scripts/python.exe Scripts/python3.dll Scripts/pysetup3.exe Scripts/pysetup3-script.py ... other DLLs and pyds... Include/ Lib/site-packageThird-party packages installed into the virtual environment will have their Python modules placed in the
site-packagesdirectory, and their executables placed inbin/orScripts. -
Splitting the meanings of sys.prefix
sys.prefixis describes as “A string giving thesite-specificdirectory prefix where the platform independent Python files are installed.” Bu default, this is the string'/usr/local'.If a virtual environment is in effect, this value will be changed in
site.pyto point to the virtual environment. The value for the Python installation will still be avaiable, viabase_prefix.The standard library and header files as found under
sys.prefix, but without site-packages. -
安装及使用
python标准库
不同于作为application的
virtualenv,venv更多是作为module library存在,当然也可以通过python -m venv来调用scripts.python -m venv pro source pro/bin/activate # 激活 deactivate rm -rf pro -
References
- [Lib/venv/ : Creation of virtual environments](Lib/venv/ : Creation of virtual environments )
本文详细介绍了Python中venv模块的功能与使用方法。venv模块用于创建轻量级虚拟环境,支持独立的site目录,并能选择性地隔离系统目录。文章还解释了虚拟环境的布局,并说明了如何通过venv模块进行安装与使用。
842

被折叠的 条评论
为什么被折叠?



