Preface
After installing tools such as Python and pip,setuptools, you can create a virualenv virtual environment, a virtual machine-like tool that allows you to run multiple versions of a Python program on the same computer, without affecting each other, and quitting or deleting it when not in use. It's a very good development tool.
First, install the virtualenv
#install pip on macbrew install Pythoncurl https://bootstrap.pypa.io/ez_setup.py-o-| sudo pythonsudo easy_install pip#install virtualenv by Pippip install virtualenv
Second, the use of virtualenv
#创建一个叫做pythonEnv的新环境virtualenv pythonenv# Activate and then use the CD Pythonenvsource bin/activate# to exit the environment deactivate
Third, use Virtualenvwrapper to manage the virtual environment
Installing Virtualenvwrapper
Pip Install Virtualenvwrapper
To configure environment variables:
Vim ~/.bash_profile# virtualenv/virtualenvwrappersource/usr/local/bin/virtualenvwrapper.sh# exit Vimsource ~/.bash_ Profile
Create an environment
Mkvirtualenv pythonenv #在 ~/envs Create a pythonenv folder mkvirtualenv python3env-p python3.5 #创建python3.5 environment
To switch environments:
Workon pythonenv
Exit the Environment:
Deactivate
To delete an environment:
Rmvirtualenv pythonenv
Other
1. Other commands
Lsvirtualenv #列举所有的环境. Cdvirtualenv #导航到当前激活的虚拟环境的目录中, for example, so you can browse its site-packages. Cdsitepackages #和上面的类似, but is directly into the Site-packages directory. Lssitepackages #显示 content in the Site-packages directory.
2. When installing PIP using the Easy_install command, the Importerror:no module named extern error appears
Cause: The extern module of the Mac comes with python2.7.12 is not installed
Workaround:
#download from https://pypi.python.org/pypi/extern/0.1.0 tar zxf extern-0.1.0.tar.gz && python setup.py install