virtualenv, virtualenvwrapper installation and use

 

1, the installation

 

1
2
3
# 安装:
(sudo) pip install virtualenv virtualenvwrapper  # centos7下
pip install virtualenv virtualenvwrapper - win  # windows下

 2, Configuration

2.1 Linux / Mac OSX under:

Modified ~ / .bash_profile related files or other environmental variables (e.g., with .zshrc .bashrc or after ZSH), add the following statement:

1
2
export WORKON_HOME = $HOME / .virtualenvs  # 存储虚拟环境的目录可以任意命名,不一定就是.virtualenvs
source  / usr / local / bin / virtualenvwrapper.sh  # 可以使用whereis virtualenvwrapper命令来查找sh文件的目录

Modified to make it take effect immediately (you can also restart the terminal to make it take effect):

1
source ~ / .bash_profile

 

2.2 Windows under :

The default virtual environment under Windows is placed beneath the user name of Envs, desktop, my documents, downloads and other documents in a folder of. Change the method: Computer, Properties, Advanced system settings, environment variables, adding WORKON_HOME.


3, an operation instruction

 

3.1 virtualenv

 

1
2
3
4
5
virtualenv ENV  # 当前目录下新建虚拟环境ENV
virtualenv  - - system - site - packages ENV  # 继承使用系统全局库地创建
virtualenv  - / usr / bin / python2. 7  env  # 指定python版本地创建,centos7下
virtualenv  - p D:\install\anaconda\python.exe env  # 指定python版本地创建,windows下
virtualenv  - - version  # 查看virtualenv版本号

ENV directory that creates a new virtual environment.

Commonly used parameters:
-p : specify a version of python environment; usually installed will be used when multiple versions of python on your system; virtualenv default prefers the python its host environment, namely that it is installed python the next version will be the default choice which version as the default python isolated environment.
Packages Standard Package-Site---no : do not use the system environment python installation package that can not be used in isolation package installation package python real environment; the current version of this option is the default.
Packages-Site---system : contrast to the above, that the python isolation environment access system environment installation package
--distribute : a python environment branch to a copy, is installed by default setup, pip, wheel and other basic modules

pip and setuptools automatically downloaded in a virtual environment, you can use these tools to download python package.

linux under:

Python downloaded package in ENV / lib / pythonX.X / site-packages in.

Currently used as the python interpreter ENV / bin / python.

windows under:

Download the python package in ENV \ Lib \ site-packages in.

python interpreter currently used for the ENV \ Scripts \ python.exe.

Activation and exit the virtual environment :

1
2
3
4
5
6
7
8
9
10
11
#windows下:
cd D:\myenvs  # 进入虚拟环境目录
cd env\Scripts  # 进入脚本目录
activate.bat  # 激活虚拟环境
deactivate.bat  # 退出虚拟环境
rm  - r D:\myenvs\env  # 删除虚拟环境,必须要先退出虚拟环境 
 
#centos7下
source 虚拟环境目录 / env / bin / activate  # 在虚拟环境主目录,激活虚拟环境。
deactivate  # 退出虚拟环境
rm  - / path / to / env  # 删除虚拟环境,必须要先退出虚拟环境

 

3.2 virtualenvwrapper

mkvirtualenv environment names: Creating the environment

workon: a list of currently existing environment

workon Environmental name: Select the environment

rmvirtualenv Environmental name: delete the environment

mkproject mic: Creating runtime environment mic and mic project

mktmpenv: Create a temporary runtime environment

lsvirtualenv: Lists the available operating environment

cdvirtualenv: enter the virtual environment directory

cdsitepackages: site-packages directory into the virtual environment

lssitepackages: Lists the current environment installed the package

deactivate: Quit environment

4, the use of some

 

4.1 packages Migrating

Located within the virtual environment:

1
2
pip freeze > requirements.txt  # 环境迁出,txt文件可以任意命名
pip install  - r requirements.txt  # 环境迁入

 

4.2 introduction of opencv

 

1
2
# centos7下<br>cd 虚拟环境根目录/lib/python2.7/site-packages
ln  - sf  / usr / local / lib / python2. 7 / site - packages / cv2.so cv2.so

 Under windows: Copy the folder cv2.pyd to the virtual environment from a local site-packages file site-packages folder

4.3 .pth file import module

 In the virtual environment root directory /lib/python2.7/site-packages, New .pth file, add modules need to call the path to

1, the installation

 

1
2
3
# 安装:
(sudo) pip install virtualenv virtualenvwrapper  # centos7下
pip install virtualenv virtualenvwrapper - win  # windows下

 2, Configuration

2.1 Linux / Mac OSX under:

Modified ~ / .bash_profile related files or other environmental variables (e.g., with .zshrc .bashrc or after ZSH), add the following statement:

1
2
export WORKON_HOME = $HOME / .virtualenvs  # 存储虚拟环境的目录可以任意命名,不一定就是.virtualenvs
source  / usr / local / bin / virtualenvwrapper.sh  # 可以使用whereis virtualenvwrapper命令来查找sh文件的目录

Modified to make it take effect immediately (you can also restart the terminal to make it take effect):

1
source ~ / .bash_profile

 

2.2 Windows under :

The default virtual environment under Windows is placed beneath the user name of Envs, desktop, my documents, downloads and other documents in a folder of. Change the method: Computer, Properties, Advanced system settings, environment variables, adding WORKON_HOME.


3, an operation instruction

 

3.1 virtualenv

 

1
2
3
4
5
virtualenv ENV  # 当前目录下新建虚拟环境ENV
virtualenv  - - system - site - packages ENV  # 继承使用系统全局库地创建
virtualenv  - / usr / bin / python2. 7  env  # 指定python版本地创建,centos7下
virtualenv  - p D:\install\anaconda\python.exe env  # 指定python版本地创建,windows下
virtualenv  - - version  # 查看virtualenv版本号

ENV directory that creates a new virtual environment.

Commonly used parameters:
-p : specify a version of python environment; usually installed will be used when multiple versions of python on your system; virtualenv default prefers the python its host environment, namely that it is installed python the next version will be the default choice which version as the default python isolated environment.
Packages Standard Package-Site---no : do not use the system environment python installation package that can not be used in isolation package installation package python real environment; the current version of this option is the default.
Packages-Site---system : contrast to the above, that the python isolation environment access system environment installation package
--distribute : a python environment branch to a copy, is installed by default setup, pip, wheel and other basic modules

pip and setuptools automatically downloaded in a virtual environment, you can use these tools to download python package.

linux under:

Python downloaded package in ENV / lib / pythonX.X / site-packages in.

Currently used as the python interpreter ENV / bin / python.

windows under:

Download the python package in ENV \ Lib \ site-packages in.

python interpreter currently used for the ENV \ Scripts \ python.exe.

Activation and exit the virtual environment :

1
2
3
4
5
6
7
8
9
10
11
#windows下:
cd D:\myenvs  # 进入虚拟环境目录
cd env\Scripts  # 进入脚本目录
activate.bat  # 激活虚拟环境
deactivate.bat  # 退出虚拟环境
rm  - r D:\myenvs\env  # 删除虚拟环境,必须要先退出虚拟环境 
 
#centos7下
source 虚拟环境目录 / env / bin / activate  # 在虚拟环境主目录,激活虚拟环境。
deactivate  # 退出虚拟环境
rm  - / path / to / env  # 删除虚拟环境,必须要先退出虚拟环境

 

3.2 virtualenvwrapper

mkvirtualenv environment names: Creating the environment

workon: a list of currently existing environment

workon Environmental name: Select the environment

rmvirtualenv Environmental name: delete the environment

mkproject mic: Creating runtime environment mic and mic project

mktmpenv: Create a temporary runtime environment

lsvirtualenv: Lists the available operating environment

cdvirtualenv: enter the virtual environment directory

cdsitepackages: site-packages directory into the virtual environment

lssitepackages: Lists the current environment installed the package

deactivate: Quit environment

4, the use of some

 

4.1 packages Migrating

Located within the virtual environment:

1
2
pip freeze > requirements.txt  # 环境迁出,txt文件可以任意命名
pip install  - r requirements.txt  # 环境迁入

 

4.2 introduction of opencv

 

1
2
# centos7下<br>cd 虚拟环境根目录/lib/python2.7/site-packages
ln  - sf  / usr / local / lib / python2. 7 / site - packages / cv2.so cv2.so

 Under windows: Copy the folder cv2.pyd to the virtual environment from a local site-packages file site-packages folder

4.3 .pth file import module

 In the virtual environment root directory /lib/python2.7/site-packages, New .pth file, add modules need to call the path to

Guess you like

Origin www.cnblogs.com/zixinyu/p/11308659.html