概述
-
virtual environment
PEP405 – Python Virtual Environments
The utility of Python virtual Environments has already been well established by the popularity of existing third-party virtual-environment tools, primarily I a n B i c k i n g Ian Bicking IanBicking's virtualenv.
Virtual environments are already widely used for dependency management and isolation.
由于缺乏Python的原生支持,早期的虚拟环境工具 don’t copy the Python binary into the virtual environment, cannot provide reliable isolation from system site directories.
Virtualenv
which does copy the Python binary, is forced to dumplicate much of Python’ssite
module and manually symlink/copy an ever-changing set of standard-library modules into the virtual environment in order to perform a delicate boot-strapping dance at every startup.(virtualenv
must copy the binary in order to provide isolation,as Python dereferences a symlinked executable before searching forsys.prefix
)By default, a virtual environment is entirely isolated from the system-level site-packages directories.
-
virtualenv & virtuanlenvwrapper & Virtualenv Burrito
-
Virtualenv
virtualenv
is a tool to create isolated Python environments written by Mozilla’s own Ian Bicking(author ofpip
too).The functionality is now going to be built more directly into Python itself, but
virtualenv
remains very popular for managing projects.It’s just the right level of hack to get everything to work consistently and well.
Since
Python 3.3
, a subset of it has been integrated into the standard library under thevenv
module.The
venv
module does not offer all features of this library, to name just a few more prominent:- is slower (by not having the
app-data
seed method) - is not as extendable
- cannot create virtual environments for arbitrarily installed python versions (and automatically discover these)
- is not upgrade-able via
pip
- does not have as rich programmatic API (describe virtual environments without creating them)
virtualenv
creates an environment that has its own installation directories, that doesn’t share libraries with other virtualenv environments(and optionally doesn’t access the globally installed libraries either) - is slower (by not having the
-
virtualenvwrapper
virtualenvwrapper
is a set of extensions to lan Bicking’s virtualenv tool. -
Virtualenv Burrito
With one command, have a working Python
virtualenv
+virtualenvwrapper
environment, 两年前已停止更新。 -
Virtualenv 开发起源
site-packages Considered Harmful
[Distutils] API for finding plugins
From Ian Bicking, he think site-packages is a bad idea, and that is should be empty and maybe not even on
sys.path
at all.There are a lot of different things you can do with
$PYTHONPATH
,sitecustomize
,.pth
files, and othersys.path
modifications.The order in which you do things can matter a lot. This all sucks.
Instead there should be a global installation of the standard library, plus those boring/stable libraries that can practically be considered “standard”. And that’s the only globally installed thing at all. Everything else is only installed in a specific context.
-
安装
关于
pipx
参见 《理解pipx VS. pip end-user application.md》virtualenv
is a CLI tool that needs a Python interpreter to run.The best is to use
pipx
to installvirtualenv
into an isolated environment.This has the added benefit that later you’ll be able to upgrade virtualenv without affecting other parts of the system.
python -m pip install --user pipx python -m pipx ensurepath pipx install virtualnev
-
使用
virtualenv command flags
How to use Python virtualenv
virtual venv cd venv source bin/activate deactivate rm -rf venv/
-
关于删除virtual environment
There is no command for deleting your virtual enviroment. Simply deactivate it and rid your application of its arifacts by recursively removing it.
This is the same regardless of what kind of virtual environment you are using.
virtualenv
,venv
,Anaconda environment
,pyenv
,pipenv
are all based the same priciple here.
-
-
References
- Virtualenv
- Pipenv & Virtual Environments
- The Hitchhiker’s Guide to Python!
- 廖雪峰的官方网站
- How do I remove/delete a virtualenv?
最后
以上就是谨慎柠檬为你收集整理的深入理解Virtual Environment Virtualenv in Python的全部内容,希望文章能够帮你解决深入理解Virtual Environment Virtualenv in Python所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复