【python】python环境搭建
本文主要用于记录python环境的搭建一些不常用的命令,其他的安装步骤在其他大师可以找到就不详细列出了。(注:以下操作都是在Ubuntu14.04LTS版本)
一.环境查询相关
1.查询当前python环境中安装的包及版本信息。
pip freeze
二.虚拟环境相关
1.使用virtualenv建立虚拟环境
jones@ubuntu:~$ export VIRTUAL_USE_DISTRIBUTE=true jones@ubuntu:~$ mkdir ~/work jones@ubuntu:~$ cd ~/work/ jones@ubuntu:~/work$ virtualenv env
2.虚拟环境激活
jones@ubuntu:~/work$ source env/bin/activate (env) jones@ubuntu:~/work$
3.退出虚拟环境
(env) jones@ubuntu:~/work$ deactivate jones@ubuntu:~/work$
4.强大的virtualenvwrapper
(1)安装virtualenvwrapper
jones@ubuntu:~/work$ pip install virtualenvwrapper
(2)修改.bashrc
jones@ubuntu:~/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环境
jones@ubuntu:~/work$ source ~/.bashrc
(4)创建虚拟环境
jones@ubuntu:~/work$ mkvirtualenv newenv
(newenv) jones@ubuntu:~/work$
(5)退出虚拟环境
(newenv) jones@ubuntu:~/work$ deactivate
jones@ubuntu:~/work$
(6)进入虚拟环境
jones@ubuntu:~/work$ workon newenv
(newenv) jones@ubuntu:~/work$
(7)查看当前环境里面的虚拟环境
jones@ubuntu:~/work$ workon
newenv
(8)删除虚拟环境
jones@ubuntu:~/work$ rmvirtualenv newenv Removing newenv... jones@ubuntu:~/work$ workon jones@ubuntu:~/work$
5.使用不同版本的python(通过虚拟环境实现)
Python2.7 jones@ubuntu:~/work$ mkvirtualenv --python=/usr/bin/python2.7 newenv2 Python3.4 jones@ubuntu:~/work$ mkvirtualenv --python=/usr/bin/python3.4 newenv3