Python Virtual Environment virualenv installation and use, pythonvirualenv

Source: Internet
Author: User
Tags virtual environment virtualenv

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.

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.