How to install and use Python virtual environment virualenv

Source: Internet
Author: User
Tags virtual environment virtualenv
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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.