python 2.7.11 环境安装
0 安装依赖:
yum install zlib zlib-devel readline-devel sqlite-devel bzip2-devel openssl-devel gdbm-devel libdbi-devel ncurses-libs kernel-devel libxslt-devel libffi-devel python-devel mysql-devel zlib-devel mysql-server sshpass -y
1 安装python2.7.11
wget http://mirrors.sohu.com/python/2.7.11/Python-2.7.11.tgz tar -xzvf Python-2.7.11.tgz cd Python-2.7.11 ./configure --prefix=/data/soft/python2.7 make make install # 备份python2.6文件: mv /usr/bin/python /usr/bin/python2.6.6 # vim /usr/bin/yum 将文件头部的 #!/usr/bin/python 改成 #!/usr/bin/python2.6.6
2 修改用户环境变量:
vim /root/.bash_profile # 修改内容如下: PYTHON_HOME=/data/soft/python2.7 export PYTHON_HOME PATH=$PYTHON_HOME/bin:$PATH:$HOME/bin export PATH # 保存退出 source /root/.bash_profile # 或者重新登录 # 验证python版本: [root@VM_128_212_centos opt]# python Python 2.7.11 (default, Jul 24 2017, 11:12:15) [GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> exit(); [root@VM_128_212_centos opt]# which python /data/soft/python2.7/bin/python [root@VM_128_212_centos opt]#
3 安装easy_install
wget --no-check-certificate https://pypi.python.org/packages/f7/94/eee867605a99ac113c4108534ad7c292ed48bf1d06dfe7b63daa51e49987/setuptools-28.0.0.tar.gz#md5=9b23df90e1510c7353a5cf07873dcd22 tar -xzvf setuptools-28.0.0.tar.gz cd setuptools-28.0.0 python setup.py install
4 安装pip
wget --no-check-certificate https://github.com/pypa/pip/archive/1.5.5.tar.gz -O pip-1.5.5.tar.gz tar -xzvf pip-1.5.5.tar.gz cd pip-1.5.5/ python setup.py install
5 ipython 安装:
# ipython安装需要升级pip到9.0.1以上: pip install --upgrade pip # 安装ipython: pip install ipython # 验证ipython: pip list #进入 ipython [root@VM_128_212_centos bin]# ipython /data/soft/python2.7/lib/python2.7/site-packages/IPython/core/history.py:228: UserWarning: IPython History requires SQLite, your history will not be saved warn("IPython History requires SQLite, your history will not be saved") Python 2.7.11 (default, Jul 24 2017, 11:12:15) Type "copyright", "credits" or "license" for more information. IPython 5.4.1 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. In [1]:
6 virtualenv 环境安装:
# 安装虚拟环境:
pip install virualenv # 创建虚拟环境: virtualenv web99 [root@VM_128_212_centos test]# virtualenv web99 New python executable in /data/test/web99/bin/python Installing setuptools, pip, wheel...done. # 进入虚拟环境: cd web99/bin/ source activate [root@VM_128_212_centos bin]# source activate (web99) [root@VM_128_212_centos bin]# python Python 2.7.11 (default, Jul 24 2017, 11:12:15) [GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> exit() (web99) [root@VM_128_212_centos bin]# ls activate activate.fish easy_install pip pip2.7 python-config python2.7 activate.csh activate_this.py easy_install-2.7 pip2 python python2 wheel # 退出虚拟环境: deactivate