Home > Backend Development > Python Tutorial > Detailed explanation of the installation and use of python virtual environment virualenv

Detailed explanation of the installation and use of python virtual environment virualenv

高洛峰
Release: 2017-03-24 17:27:31
Original
1866 people have browsed it

Preface
After installing python, pip, setuptools and other tools, you can create a virualenv virtual environment. This tool, similar to a virtual machine, can run multiple programs on the same computer. Different versions of python programs do not affect each other. You can exit or delete them when not in use. It is a good development tool.
1. Install virtualenv

#install pip on mac
brew install python
curl https://bootstrap.pypa.io/ez_setup.py -o - | sudo python
sudo easy_install pip
#install virtualenv by pip
pip install virtualenv
Copy after login


2. Use of virtualenv

#创建一个叫做pythonEnv的新环境
virtualenv pythonEnv
#激活再使用
cd pythonEnv
source bin/activate
#退出环境
deactivate
Copy after login


3. Use virtualenvwrapper manages virtual environments
Install virtualenvwrapper

pip install virtualenvwrapper
Copy after login


Configure environment variables:

vim ~/.bash_profile
# Virtualenv/VirtualenvWrapper
source /usr/local/bin/virtualenvwrapper.sh
# exit vim
source ~/.bash_profile
Copy after login


Create environment

mkvirtualenv pythonEnv #在 ~/Envs 中创建 pythonEnv文件夹
mkvirtualenv python3Env -p python3.5 #创建python3.5的环境
Copy after login


Switch environment:

workon pythonEnv
Copy after login


Exit environment:

deactivate
Copy after login


Delete environment:

rmvirtualenv pythonEnv
Copy after login


Others
1. Other commands

lsvirtualenv #列举所有的环境。
cdvirtualenv #导航到当前激活的虚拟环境的目录中,比如说这样你就能够浏览它的 site-packages 。
cdsitepackages #和上面的类似,但是是直接进入到 site-packages 目录中。
lssitepackages #显示 site-packages 目录中的内容。
Copy after login

2. When using the easy_install command to install pip, an ImportError: No module named extern error occurs
Cause: The extern module of python2.7.12 that comes with mac is not installed
Solution:

#download from https://pypi.python.org/pypi/extern/0.1.0 tar zxf extern-0.1.0.tar.gz && python setup.py install
Copy after login

The above is the detailed content of Detailed explanation of the installation and use of python virtual environment virualenv. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template