安装
Alexs-Mac:experience alex$ pip install virtualenv Downloading/unpacking virtualenv Downloading virtualenv-1.11.4-py2.py3-none-any.whl (1.7MB): 1.7MB downloaded Installing collected packages: virtualenv Successfully installed virtualenv Cleaning up...
建立虚拟环境
Alexs-Mac:my alex$ mkdir alog Alexs-Mac:my alex$ cd alog/ Alexs-Mac:alog alex$ ls -la total 0 drwxr-xr-x 2 alex staff 68 Apr 28 10:29 . drwxr-xr-x 15 alex staff 510 Apr 28 10:29 .. Alexs-Mac:alog alex$ virtualenv venv New python executable in venv/bin/python Installing setuptools, pip...done. Alexs-Mac:alog alex$ ls -la total 0 drwxr-xr-x 3 alex staff 102 Apr 28 10:31 . drwxr-xr-x 15 alex staff 510 Apr 28 10:29 .. drwxr-xr-x 5 alex staff 170 Apr 28 10:31 venv
激活虚拟环境
Alexs-Mac:alog alex$ source venv/bin/activate (venv)Alexs-Mac:alog alex$ python Python 2.7.6 (default, Apr 17 2014, 13:46:37) [GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> exit()
在虚拟环境中安装Package
(venv)Alexs-Mac:tools alex$ pip install requests Downloading/unpacking requests Downloading requests-2.2.1-py2.py3-none-any.whl (625kB): 625kB downloaded Installing collected packages: requests Successfully installed requests Cleaning up...
在虚拟环境中使用Package
(venv)Alexs-Mac:tools alex$ python Python 2.7.6 (default, Apr 17 2014, 13:46:37) [GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import requests >>> help(requests) >>> exit()
退出虚拟环境
(venv)Alexs-Mac:tools alex$ deactivate Alexs-Mac:tools alex$
参考