Python Virtual Environment virualenv installation and use, pythonvirualenv
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.
References: http://virtualenvwrapper.readthedocs.io/en/latest/command_ref.html
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.0tar zxf extern-0.1.0.tar.gz && python setup.py install
Summary
The above is all about this article. I hope this article will help you in your study or work. If you have any questions, please leave a message.