深入理解Virtual Environment Virtualenv in Python

  • 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’s site 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 for sys.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 of pip 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 the venv 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)

  • 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 other sys.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 install virtualenv 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

  1. Virtualenv
  2. Pipenv & Virtual Environments
  3. The Hitchhiker’s Guide to Python!
  4. 廖雪峰的官方网站
  5. How do I remove/delete a virtualenv?
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值