本文主要用于记录python环境的搭建一些不常用的命令,其他的安装步骤在其他大师可以找到就不详细列出了。(注:以下操作都是在Ubuntu14.04LTS版本)
一.环境查询相关
1.查询当前python环境中安装的包及版本信息。
pip freeze
二.虚拟环境相关
1.使用virtualenv建立虚拟环境
[email protected]:~$ export VIRTUAL_USE_DISTRIBUTE=true [email protected]:~$ mkdir ~/work [email protected]:~$ cd ~/work/ [email protected]:~/work$ virtualenv env
2.虚拟环境激活
[email protected]:~/work$ source env/bin/activate (env) [email protected]:~/work$
3.退出虚拟环境
(env) [email protected]:~/work$ deactivate [email protected]:~/work$
4.强大的virtualenvwrapper
(1)安装virtualenvwrapper
[email protected]:~/work$ pip install virtualenvwrapper
(2)修改.bashrc
[email protected]:~/work$ vim ~/.bashrc
if [ -f /usr/local/bin/virtualwrapper.sh ]; then export WORKON_HOME=$HOME/.virtualenvs source /usr/local/bin/virtualenvwrapper.sh fi
(3)更新.bashrc环境
[email protected]:~/work$ source ~/.bashrc
(4)创建虚拟环境
[email protected]:~/work$ mkvirtualenv newenv (newenv) [email protected]:~/work$
(5)退出虚拟环境
(newenv) [email protected]:~/work$ deactivate [email protected]:~/work$
(6)进入虚拟环境
[email protected]:~/work$ workon newenv (newenv) [email protected]:~/work$
(7)查看当前环境里面的虚拟环境
[email protected]:~/work$ workon newenv
(8)删除虚拟环境
[email protected]:~/work$ rmvirtualenv newenv Removing newenv... [email protected]:~/work$ workon [email protected]:~/work$
5.使用不同版本的python(通过虚拟环境实现)
Python2.7 [email protected]:~/work$ mkvirtualenv --python=/usr/bin/python2.7 newenv2 Python3.4 [email protected]:~/work$ mkvirtualenv --python=/usr/bin/python3.4 newenv3
时间: 2024-11-08 17:27:59