python virtual environment --virtualenv python virtual environment --virtualenv

python virtual environment --virtualenv

 

  virtualenv is a tool to create isolated Python environment. Virtualenv create a file that contains all the necessary executable files, and to use the required engineering Python package.

  installation

pip install virtualenv

  Basic use

  1. Create a virtual environment for a project:
Cd my_project_dir $ 
$ virtualenv Venv  #venv virtual environment directory name, directory name, custom

  virtualenv venv Will be created in the current directory in a folder that contains Python executable file, and  pip a copy of the library, so you can install additional package. Virtual environment name (in this case is  venv ) can be arbitrary; if the file name will be omitted are in the current directory.

  In any directory you run the command, which creates a copy of Python, and the place is called the  venv file.

  You can choose to use a Python interpreter:

Virtualenv -p /usr/bin/python2.7 Venv $     # -p parameter specifies the path to the Python interpreter program

  This will use  /usr/bin/python2.7 the Python interpreter.

 

  1. To start using a virtual environment, it needs to be activated:
$ source venv/bin/activate   

从现在起,任何你使用pip安装的包将会放在 venv Folder, and cut off from the global installation of Python.

Usual installation package, such as:

$ pip install requests
  1. If you temporarily completed the work in a virtual environment, you can disable it:
$ . venv/bin/deactivate

It will return to the default Python interpreter, including installed library will return to the default.

To delete a virtual environment, simply delete its folder. (Execution   ).rm -rf venv

Here virtualenv some inconvenience, because virtual start, stop scripts in a specific folder, probably after some time, you may have a lot of virtual environments scattered throughout the system, you might forget their names or location.

virtualenvwrapper

  Given virtualenv not easy centralized management of virtual environments, it is recommended to use direct virtualenvwrapper. virtualenvwrapper provides a set of command and make virtual work environment is facilitated. It put all your virtual environment in one place.

  Installation virtualenvwrapper (virtualenv make sure you have installed)

virtualenvwrapper the install PIP 
PIP-win the install virtualenvwrapper # Windows This command

  After installation is complete, the following is written in ~ / .bashrc

export WORKON_HOME=~/Envs
source /usr/local/bin/virtualenvwrapper.sh  

  The first line: virtualenvwrapper virtual environment storage directory

  The second line: virtrualenvwrapper installed to python bin directory, so the path is python installation directory bin / virtualenvwrapper.sh

source ~ / .bashrc # reads the configuration file, with immediate effect

 

 virtualenvwrapper basic use

1. Create a virtual environment mkvirtualenv

mkvirtualenv venv   

  This will create a new virtual environment called venv in WORKON_HOME variable specified directory.

  To specify python version, python interpreter can be specified by "--python"

mkvirtualenv --python=/usr/local/python3.5.3/bin/python venv

2. Basic Commands  

  View the current directory virtual environment

[root@localhost ~]# workon
py2
py3

  Switch to the virtual environment

[root@localhost ~]# workon py3
(py3) [root@localhost ~]# 

  Exit Virtual Environment

(py3) [root@localhost ~]# deactivate
[root@localhost ~]# 

  Delete the virtual environment

rmvirtualenv venv

 

 

This article reference links: http: //pythonguidecn.readthedocs.io/zh/latest/dev/virtualenvs.html

 

  virtualenv is a tool to create isolated Python environment. Virtualenv create a file that contains all the necessary executable files, and to use the required engineering Python package.

  installation

pip install virtualenv

  Basic use

  1. Create a virtual environment for a project:
Cd my_project_dir $ 
$ virtualenv Venv  #venv virtual environment directory name, directory name, custom

  virtualenv venv Will be created in the current directory in a folder that contains Python executable file, and  pip a copy of the library, so you can install additional package. Virtual environment name (in this case is  venv ) can be arbitrary; if the file name will be omitted are in the current directory.

  In any directory you run the command, which creates a copy of Python, and the place is called the  venv file.

  You can choose to use a Python interpreter:

Virtualenv -p /usr/bin/python2.7 Venv $     # -p parameter specifies the path to the Python interpreter program

  This will use  /usr/bin/python2.7 the Python interpreter.

 

  1. To start using a virtual environment, it needs to be activated:
$ source venv/bin/activate   

从现在起,任何你使用pip安装的包将会放在 venv Folder, and cut off from the global installation of Python.

Usual installation package, such as:

$ pip install requests
  1. If you temporarily completed the work in a virtual environment, you can disable it:
$ . venv/bin/deactivate

It will return to the default Python interpreter, including installed library will return to the default.

To delete a virtual environment, simply delete its folder. (Execution   ).rm -rf venv

Here virtualenv some inconvenience, because virtual start, stop scripts in a specific folder, probably after some time, you may have a lot of virtual environments scattered throughout the system, you might forget their names or location.

virtualenvwrapper

  Given virtualenv not easy centralized management of virtual environments, it is recommended to use direct virtualenvwrapper. virtualenvwrapper provides a set of command and make virtual work environment is facilitated. It put all your virtual environment in one place.

  Installation virtualenvwrapper (virtualenv make sure you have installed)

virtualenvwrapper the install PIP 
PIP-win the install virtualenvwrapper # Windows This command

  After installation is complete, the following is written in ~ / .bashrc

export WORKON_HOME=~/Envs
source /usr/local/bin/virtualenvwrapper.sh  

  The first line: virtualenvwrapper virtual environment storage directory

  The second line: virtrualenvwrapper installed to python bin directory, so the path is python installation directory bin / virtualenvwrapper.sh

source ~ / .bashrc # reads the configuration file, with immediate effect

 

 virtualenvwrapper basic use

1. Create a virtual environment mkvirtualenv

mkvirtualenv venv   

  This will create a new virtual environment called venv in WORKON_HOME variable specified directory.

  To specify python version, python interpreter can be specified by "--python"

mkvirtualenv --python=/usr/local/python3.5.3/bin/python venv

2. Basic Commands  

  View the current directory virtual environment

[root@localhost ~]# workon
py2
py3

  Switch to the virtual environment

[root@localhost ~]# workon py3
(py3) [root@localhost ~]# 

  Exit Virtual Environment

(py3) [root@localhost ~]# deactivate
[root@localhost ~]# 

  Delete the virtual environment

rmvirtualenv venv

 

 

This article reference links: http: //pythonguidecn.readthedocs.io/zh/latest/dev/virtualenvs.html

 

Guess you like

Origin www.cnblogs.com/HHHAI/p/11123006.html