I've long heard that virtualenv is one of the essential artifacts of Python, But always feel that the Mac python2.7 is very easy to use, as if there is no need for virtualenv, but today on the GitHub to see a new Python open source project, need to use Python3, so must virtualenv.
1. Install virtualenv, 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 (List of notes. Localpython)
Make
Make install
3. Create an environment
Mkvirtualenv env27
Mkvirtualenv-p/users/heliclei/.localpython/bin/python3.4 env34 (notes. Localpython directory)
This creates the python2.7 and 3.4 Two versions of the virtual environment, respectively.
4. Switch
Workon env27
Look at the Python version.
Python--version
>>python 2.7.6
and cut to 3.4 of the environment.
Workon env34
Check the version.
Python--version
>>python 3.4.0
It appears that two versions of Python are working correctly:
5.
Exit Environment: Deactivate
Delete environment: Rmvirtualenv env_name
Reprinted from: http://www.2cto.com/os/201412/365570.html (verified available.) )