What is Virtualenv?
Virtualenv is used to create multiple standalone Python runtime environments on a single machine, Virtualenvwrapper provides some handy package on the command line.
Why do you use
-Isolation of third-party package dependencies between projects, such as a project dependent on Django1.2.5,b project dependent django1.3.
-To facilitate the deployment of applications, the development environment of the virtual environment packaged in a production environment, do not need to be on the server again.
How to use
Installation
-Pip Install Virtualenvwrapper
-Add the following sentence to the ~/.bash_profile inside, if not too troublesome, can also be manually executed each time.
Export Workon_home= $HOME/.virtualenvssource/usr/bin/virtualenvwrapper.sh
Note the path to virtualenvwrapper.sh here
/usr/bin/virtualenvwrapper.sh
Common commands
An innovative virtual environment
-Mkvirtualenv [ENV1]
This command will help us create a new environment, by default, the directory of the environment is. VIRTUALENV/EN1, which automatically installs the PIP for us during the creation process, and can be used to directly use the PIP command when we install new dependencies.
Once created, automatically switches to work in that environment, and you can see that the prompt changes to:
(ENV1) $
Dependencies installed in this environment do not affect other environments
-Lssitepackages shows the packages installed in the environment
Toggle Environment
-Workon [env]
Use "Workon environment name" at any time to make an environment switch, and if you do not have an environment name parameter, display the currently used environment
-deactivate
in an environment. Switch to the system's Python environment
Other commands
-Showvirtualenv [env] Displays details of the specified environment.
-Rmvirtualenv [env] Removes the specified virtual environment, as long as the removal is not currently working in that environment. If working in this environment, first use deactivate to exit.
-cpvirtualenv [Source] [dest] Copies a copy of the virtual environment.
-Cdvirtualenv [SubDir] Sets the current working directory to the Environment directory in which it resides.
-Cdsitepackages [SubDir] Sets the current working directory to the Sitepackages path of the environment in which it is located.
-Add2virtualenv [dir] [dir] adds the specified directory to the path of the currently used environment, which is often used in situations where a larger library is used simultaneously in multiple project.
-Toggleglobalsitepackages-q Controls whether the current environment uses a global sitepackages directory
Python builds multi-version environment--pyenv, Virtualenv toss notes continued