Pythonbrew 可以在多个 Python之间迅速切换,也可以在指定的 Python 版本下测试python程序,更重要的是它还整合了上一篇文章提到的 Virtualenv。所以,当你的电脑里装了多个python版本,并需要经常切换测试时,pythonbrew就非常适合你。
安装配置pythonbrew
alexzhou@alexzhou:~/python_workspace$ sudo easy_install pythonbrew alexzhou@alexzhou:~/python_workspace$ pythonbrew_install添加:
[[ -s "$HOME/.pythonbrew/etc/bashrc" ]] && source "$HOME/.pythonbrew/etc/bashrc"
到~/.bashrc最后。
然后执行:source ~/.bashrc
查看系统可以安装的python版本
alexzhou@alexzhou:~/python_workspace$ pythonbrew list --know # Pythons Python-1.5.2 Python-1.6.1 Python-2.0.1 Python-2.1.3 Python-2.2.3 Python-2.3.7 Python-2.4.6 Python-2.5.6 Python-2.6.7 Python-2.7.3 Python-3.0.1 Python-3.1.4 Python-3.2.3
alexzhou@alexzhou:~/python_workspace$ pythonbrew install 3.2.3 pythonbrew required curl. curl was not found in your path. alexzhou@alexzhou:~/python_workspace$ sudo apt-get install curl alexzhou@alexzhou:~/python_workspace$ pythonbrew install 3.2.3 Downloading Python-3.2.3.tgz as /home/alexzhou/.pythonbrew/dists/Python-3.2.3.tgz ...... alexzhou@alexzhou:~/python_workspace$ pythonbrew install 2.6.7
alexzhou@alexzhou:~/python_workspace$ pythonbrew cleanup
alexzhou@alexzhou:~/python_workspace$ pythonbrew --help
alexzhou@alexzhou:~/python_workspace$ pythonbrew use 2.6.7 Using `Python-2.6.7`
alexzhou@alexzhou:~/python_workspace$ pythonbrew list # pythonbrew pythons Python-2.6.7 (*) Python-3.2.3
alexzhou@alexzhou:~/python_workspace$ pythonbrew switch 2.6.7
取消pythonbrew选择的版本
alexzhou@alexzhou:~/python_workspace$ pythonbrew off
alexzhou@alexzhou:~/python_workspace$ pythonbrew switch 2.6.7
alexzhou@alexzhou:~/python_workspace$ pythonbrew venv create test_env
alexzhou@alexzhou:~/python_workspace$ pythonbrew venv list # virtualenv for Python-2.6.7 (found in /home/alexzhou/.pythonbrew/venvs/Python-2.6.7) test_env
alexzhou@alexzhou:~/python_workspace$ pythonbrew venv use test_env # Using `test_env` environment (found in /home/alexzhou/.pythonbrew/venvs/Python-2.6.7) # To leave an environment, simply run `deactivate` (test_env)alexzhou@alexzhou:~/python_workspace$退出虚拟环境
(test_env)alexzhou@alexzhou:~/python_workspace$ deactivate
转载请注明来自:Alex Zhou,本文链接:http://codingnow.cn/python/438.html