參考:https://ilaotan.github.io/2015/08/24/python-virtualEnv-pycharm.htmlhtml
virtualenv用於建立相互獨立的Python環境python
安裝virtualenvgit
sudo pip install virtualenv
建立virtualenv目錄github
wanyongzhendeMacBook-Pro:~ wanyongzhen$ virtualenv testvir Using base prefix '/Library/Frameworks/Python.framework/Versions/3.6' New python executable in /Users/wanyongzhen/testvir/bin/python3.6 Also creating executable in /Users/wanyongzhen/testvir/bin/python Installing setuptools, pip, wheel...done.
切換到virtualenv目錄並進入Python虛擬環境bash
wanyongzhendeMacBook-Pro:~ wanyongzhen$ cd testvir/ wanyongzhendeMacBook-Pro:testvir wanyongzhen$ source bin/activate (testvir) wanyongzhendeMacBook-Pro:testvir wanyongzhen$ pip list pip (9.0.1) setuptools (36.4.0) wheel (0.29.0)
退出virtualenv Python虛擬環境app
(testvir) wanyongzhendeMacBook-Pro:testvir wanyongzhen$ deactivate
參考:http://www.jianshu.com/p/3abe52adfa2bpython2.7
Virtaulenvwrapper是virtualenv的擴展包,用於更方便管理虛擬環境,它能夠作:code
安裝virtualenvwrapperhtm
wanyongzhendeMacBook-Pro:testvir wanyongzhen$ sudo pip install virtualenvwrapper --upgrade --ignore-installed
建立目錄用來存放虛擬環境ip
mkdir ~/.virtualenvs
在.bash_profile中添加
export WORKON_HOME=~/.virtualenvs source /usr/local/bin/virtualenvwrapper.sh
生效
source ~/.bashrc
建立virtualenv
wanyongzhendeMacBook-Pro:~ wanyongzhen$ mkvirtualenv python2.7 --python=python2.7 wanyongzhendeMacBook-Pro:~ wanyongzhen$ mkvirtualenv python3.6 --python=python3.6
命令列表