Objective:
Python has a lot of components, sometimes the project depends on M components, and sometimes the project depends on N components, the time can easily lead to the system Python environment is bloated, thus has the virtualenv, virtualenvwrapper the existence value.
How to use:
Excerpted from--HTTP://WWW.JIANSHU.COM/P/3ABE52ADFA2B
Virtualenv is used to create a stand-alone Python environment where multiple python is independent from each other and can:
Install a new suite without permissions
Different versions of the suite can be used for different applications
Package upgrades do not affect other apps.
Installation method
1, the shell under Operation:
install python-virtualenv
2. How to use
[虚拟环境名称-也是目录名称]
3. Start the Environment
cd ENVsource ./bin/activate
Env is the virtual environment name, and all of the modules will be installed in that directory.
By default, the virtual environment relies on site packages in the system environment, and if you do not want to rely on these package, you can add the parameter--no-site-packages to establish the virtual environment:
virtualenv --no-site-packages [虚拟环境名称]
4. Exit
deactivate
If the virtual environment is not started and the PIP tool is installed, the package will be installed in the system environment, in order to avoid this, you can add the following in the ~/.BASHRC file:
export PIP_REQUIRE_VIRTUALENV=true
or let the system automatically turn on the virtual environment when the PIP is executed:
export PIP_RESPECT_VIRTUALENV=true
Virtualenvwrapper
Virtaulenvwrapper is an expansion pack for virtualenv that makes it easier to manage virtual environments and can do:
Consolidate all virtual environments in one directory
Manage (new, delete, copy) virtual environments
Quickly switch virtual environments
...
Installation method
1. Operation
install virtualenvwrapper
2. Create a directory to store the virtual environment
mkdir ~/.virtualenvs
3. Add in. bashrc
export WORKON_HOME=~/.virtualenvssource /usr/local/bin/virtualenvwrapper.sh
4. Operation:source ~/.bashrc
At this point the Virtualenvwrapper is ready to use.
Command List
Workon: List of Virtual environments
Lsvirtualenv: Ibid.
MKVIRTUALENV: New Virtual environment
Workon [Virtual Environment name]: switching Virtual environments
RMVIRTUALENV: Deleting a virtual environment
Deactivate: Leaving the virtual environment
Python creates a standalone virtual work environment method