[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