Virtualenv is used to create a stand-alone Python environment where multiple python is independent from each other and can:
1. Install the new kit without permission
2. Different applications can use different versions of the kit
3. Package upgrade does not affect other applications
Installation
sudo apt-get install python-virtualenv
How to use
virtualenv [virtual Environment name] For example, create a **env** virtual environment virtualenv ENV by default, the virtual environment relies on site packages in the system environment, This means that the installed third-party package in the system will also be installed in the virtual environment, if you do not want to rely on these package, you can add the parameters--no-site-packages set up a virtual environment virtualenv--no-site-packages [ Virtual Environment Name]
Start the virtual environment
CD Envsource./bin/activate
Note that at this point the command line one more (ENV)
, env is the virtual environment name, then all the modules will only be installed in the directory.
Exiting a virtual environment
Deactivate
Installing a Python suite in a virtual environment
The virtualenv comes with the PIP installation tool, so the kit that needs to be installed can run directly: Pip install [package name] If the virtual environment is not started and the PIP tool is installed, then the package will be installed in the system environment, in order to avoid this, you can ~/. BASHRC file Plus: Export pip_require_virtualenv=true or let the system automatically open the virtual environment when 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:
1. Integrate all virtual environments into one directory
2. Manage (add, delete, copy) virtual environments
3. Switch the virtual environment
Installation
sudo easy_install virtualenvwrapper
At this time can not use Virtualenvwrapper, the default virtualenvwrapper installed under/usr/local/bin, in fact, you need to run the virtualenvwrapper.sh file before the line, do not worry, open this file to see, There are installation steps, we set the environment according to the operation.
1, create the directory to hold the virtual environment mkdir $HOME/.VIRTUALENVS2, add lines in ~/.BASHRC: Export workon_home= $HOME/.virtualenvs3, ~/. Add line in BASHRC: Source/usr/bin/virtualenvwrapper.sh4, run: source ~/.BASHRC
At this point the Virtualenvwrapper is ready to use.
List Virtual Environment lists Workon can also use lsvirtualenv new virtual Environment mkvirtualenv [virtual Environment name] Start/switch virtual environment Workon [virtual environment name] Delete virtual Environment rmvirtualenv [virtual environment name] Leaving the virtual environment deactivate
Installation and use of virtual environment virtualenv in Linux environment