一、安装virtualenv
pip3 install virtualenv
二、利用virtualenv安装Python虚拟环境
1.创建目录:
taoyali:~ michael$ mkdir myproject
taoyali:~ michael$ cd myproject/
taoyali:myproject michael$
2.创建一个独立的Python运行环境,命名为venv:
taoyali:myproject michael$ virtualenv --no-site-packages venv
Using base prefix '/usr/local/.../Python.framework/Versions/3.4'
New python executable in venv/bin/python3.4
Also creating executable in venv/bin/python
Installing setuptools, pip, wheel...done.
3.进入虚拟环境
taoyali:myproject michael$ source venv/bin/activate
(venv)taoyali:myproject michael$
4.下面正常安装各种第三方包,并运行python命令:
(venv)taoyali:myproject michael$ pip install jinja2
...
Successfully installed jinja2-2.7.3 markupsafe-0.23
(venv)taoyali:myproject michael$ python myapp.py
...
pip list 可以查看到新安装的库
5.退出当前的venv环境,使用deactivate命令:
(venv)taoyali:myproject michael$ deactivate
taoyali:myproject michael$