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
2. Use of virtualenv
#创建一个叫做pythonEnv的新环境 virtualenv pythonEnv #激活再使用 cd pythonEnv source bin/activate #退出环境 deactivate
3. Use virtualenvwrapper manages virtual environments
Install virtualenvwrapper
pip install virtualenvwrapper
Configure environment variables:
vim ~/.bash_profile # Virtualenv/VirtualenvWrapper source /usr/local/bin/virtualenvwrapper.sh # exit vim source ~/.bash_profile
Create environment
mkvirtualenv pythonEnv #在 ~/Envs 中创建 pythonEnv文件夹 mkvirtualenv python3Env -p python3.5 #创建python3.5的环境
Switch environment:
workon pythonEnv
Exit environment:
deactivate
Delete environment:
rmvirtualenv pythonEnv
Others
1. Other commands
lsvirtualenv #列举所有的环境。 cdvirtualenv #导航到当前激活的虚拟环境的目录中,比如说这样你就能够浏览它的 site-packages 。 cdsitepackages #和上面的类似,但是是直接进入到 site-packages 目录中。 lssitepackages #显示 site-packages 目录中的内容。
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
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!