Preface after installing python, pip, setuptools, and other tools, you can create a virualenv virtual environment, which is similar to a virtual machine tool, it is a good development tool that allows the same brain to run multiple python programs of different versions without affecting each other. you can exit or delete them when you don't need them. 1. install virtualenv # installpiponmacbrewinstallpythoncurlhttps
Preface
After installing python, pip, setuptools, and other tools, you can create a virualenv virtual environment. This tool is similar to a virtual machine and allows the same brain to run multiple python programs of different versions, don't affect each other. you can exit or delete it when you don't need it. it's a good development tool.
1. install 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
II. Use of virtualenv
# Create a new environment called pythonEnv virtualenv pythonEnv # activate and then use cd pythonEnvsource bin/activate # exit the environment deactivate
III. use virtualenvwrapper to manage virtual environments
Install virtualenvwrapper
pip install virtualenvwrapper
Configure environment variables:
vim ~/.bash_profile# Virtualenv/VirtualenvWrappersource /usr/local/bin/virtualenvwrapper.sh# exit vimsource ~/.bash_profile
Create environment
Mkvirtualenv pythonEnv # In ~ /Envs create the pythonEnv folder mkvirtualenv python3Env-p python3.5 # create the python3.5 environment
Switch environment:
workon pythonEnv
Exit environment:
deactivate
Delete environment:
rmvirtualenv pythonEnv
Others
1. other commands
Lsvirtualenv # List all environments. Cdvirtualenv # navigate to the Directory of the activated virtual environment. for example, you can browse its site-packages. Cdsitepackages # is similar to the above, but directly enters the site-packages directory. Lssitepackages # displays the content in the site-packages directory.
2. the ImportError: No module named extern error occurs when pip is installed using the easy_install command.
Cause: The extern module of python2.7.12 in 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 describes how to install and use virualenv in the python virtual environment. For more information, see other related articles in the first PHP community!