1. virtualenv
Python2 and Python3 are supportive manner
1.1 Installation
pip install virtualenv
1.2 Creating project
cd my_project_folder
virtualenv my_project
Specifies the python version 1.3
virtualenv -p /usr/bin/python2.7 my_project
Or adding an environment variable configuration
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python2.7
1.4 activate the virtual environment
(Linux) source my_project/bin/activate
(Windows) my_project\Scripts\activate
1.5 Exit environment
(Linux) my_project/bin/deactivate
(Windows) my_project\Scripts\deactivate.bat
1.6 virtualenv Common command options
virtualenv [the OPTIONS] dest_dir Options: -version Display version information. - H, -help display help information. - v, -verbose increase output of background information. - Q, -quiet control information output from the background. PYTHON_EXE -p, -python = PYTHON_EXE specify the Python interpreter - the Clear Clear virtual environment dependencies, initialize the environment. -System -site- Packages Standard Package using the current library on the main Python installed. -Always - Copy not and will not use a symbolic link, copy the file directly. The -no -setuptools the Do not install setuptools in at The new new virtualenv. The -no -pip the Do not install PIP in the new virtualenv. –no-wheel Do not install wheel in the new virtualenv.
1.7 virtualenv Related Extensions
virtualenvwrapper
virtualenv expansion pack, can easily manage virtualenv
1.7.1 Installation
WORKON_HOME environment variable to specify the position of the virtual environment
(Linux) pip install virtualenvwrapper export WORKON_HOME=~/Envs source /usr/local/bin/virtualenvwrapper.sh
(Windows) PIP install virtualenvwrapper- win WORKON_HOME default is % USERPROFILE% Envs
1.7.2 Basic Usage
Create a virtual environment
mkvirtualenv myenv
Switch to the virtual environment
workon myenv
Virtual environment and project separately
mkproject my_project
virtual environment WORKON_HOME, the items in the PROJECT_HOME
Exit Virtual Environment
deactivate
Delete the virtual environment
rmvirtualenv myenv
Other uses
lsvirtualenv enumerate all environments. cdvirtualenv [subdir] to navigate to the current directory active virtual environment cdsitepackages [subdir] and similar to the above, but is direct access to the Site - packages directory lssitepackages display Site - Content packages directory showvirtualenv [ env ] displays the specified environment details cpvirtualenv [source] [dest] a copy of the virtual environment allvirtualenv implementation of a unified command for the current virtual environment add2virtualenv [ dir ] [ dir ] is added to the directory specified by the environment currently used path, which is often used for multiple project which use a large library of case toggleglobalsitepackages -q controls the current environment is to use global directory of sitepackages
virtualenv-burrito
equivalent virtualenv + virtualenvwrapper, but only supports python 2
autoenv
When .env into a directory containing, autoenv automatically activates the environment
pip install autoenv
2. venv
Python3 supportive manner, and formerly known as pyvenv, python 3.6 deprecated
2.1 to create a virtual environment
python3 -m venv /path/to/new/virtual/environment
2.2 Command Help
-m Venv python3 - H Usage: Venv [ -h] [--system-Site-Packages Standard Package] [--symlinks | --copies] [- the Clear ] [ --upgrade] [--without-PIP] [- - prompt pROMPT] ENV_DIR [ENV_DIR ...] Creates Virtual Environments Python in One or More target Directories. Positional arguments The: ENV_DIR to the Create A Directory at The Environment in . optional arguments The: -h, - help help --system-site -packages access to the virtual environment system site- rights packages directory - when symlinks when the system is not a symbolic link to the default way, try to use symbolic links instead of copying. - copies try to use symbolic links instead of copying, even if symbolic link is the platform's default mode. - the Clear before the virtual environment to create, delete virtual environment directory that already exists. - upgrade the current python, upgrade the virtual environment directory. --without- pip pip skipped upgrades or installations - prompt PROMPT prefix for the environment to provide a prompt Once AN Environment has been the Created, you May of an activate td width = wish to IT, by EG Sourcing AN of an activate Script in the ITS bin Directory.
2.3 virtual environments on different platforms activation method
Platform | Shell | Command activates the virtual environment |
Posix | bash/zsh | $ source /bin/activate |
fish | $ . /bin/activate.fish | |
csh/tcsh | $ source /bin/activate.csh | |
Windows | cmd.exe | C:> \Scripts\activate.bat |
PowerShell | C:> \Scripts\Activate.ps1 |
Transfer: https://blog.csdn.net/yezhenquan123/article/details/79313110