Virtualenv is a tool for creating an isolated python environment. VIRTUALENV Create a folder that contains all the necessary executables to use the packages required by the Python project.
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
#安装pythonbrew install Pythoncurl Https://bootstrap.pypa.io/ez_setup.py-o-| sudo pythonsudo easy_install pip# using pip to install Virtualenvpip 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
Save exit
Then execute the following command to have the system reload the configuration
SOURCE ~/.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:
#从https://pypi.python.org/pypi/extern/0.1.0 download extern, and then unzip the installation
Tar zxf extern-0.1.0.tar.gz && python setup.py install