[Python] How to Use virtualenvwrapper to switch between different versions of python?

Source: Internet
Author: User
Tags virtualenv

[Python] How to Use virtualenvwrapper to switch between different versions of python?

I have long heard that virtualenv is one of the essential artifacts of python, but I have always thought that the python 2.7 provided by mac is very useful. It seems that virtualenv is not necessary, but today I saw a new python open-source project on github, python3 is required, so virtualenv must be used.

1. Install virtualenv and virtualenvwrapper

Sudo pip install virtualenv

Sudo pip install virtualenvwrapper

2. Install python3.4

Mkdir ~ /Src

Cd ~ /Src/

Wget http://www.python.org/ftp/python/3.4.0/Python-3.4.0.tgz

Tar-zxvf Python-3.4.0.tgz

Cd Python-3.4.0

Mkdir ~ /. Localpython

./Configure -- prefix =/Users/heliclei/. localpython

Make

Make install

3. Create an environment

Mkvirtualenv env27

Mkvirtualenv-p/Users/heliclei/. localpython/bin/python3.4 env34

In this way, the virtual environments of python2.7 and 3.4 are created respectively.

4. Switch

Workon env27

Let's take a look at the python version.

Python -- version

> Python 2.7.6

Switch to a 3.4 Environment

Workon env34

Check the version

Python -- version

> Python 3.4.0

It seems that both versions of python work normally :)

5.

Exit environment: deactivate

Delete environment: rmvirtualenv env_name

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.