1..安装Development Tools
yum groupinstall -y 'development tools'
2.安装SSL、bz2、zlib来为Python的安装做好准备工作
yum install -y zlib-devel bzip2-devel openssl-devel xz-libs wget
3.下载python2.7源码包
wget https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz
3.1.解压压缩包
tar xzvf Python-2.7.10.tgz
3.2.指定安装路径
cd Python-2.7.10 ./configure --prefix=/usr/local/python2
3.3.编译并安装
make make install
3.4.创建链接将python指向2.7版本
python默认是指向2.6版本的
rm -f /usr/bin/python ln -s /usr/local/python2/bin/python /usr/bin/python
3.5.修改yum文件(yum依赖python2.6)
将
“#!/usr/bin/python” 改为centos6.5原来的python版本 #!/usr/bin/python2.6
4.pip是一个安装和管理 Python 包的工具,用它我们可以方便的拉一些依赖的库下来
4.1首先下载并安装setuptools
wget --no-check-certificate https://pypi.python.org/packages/1f/7a/6b239a65d452b04ad8068193ae313b386e6fc745b92cd4584fccebecebf0/setuptools-25.1.6.tar.gz tar -xvf setuptools-25.1.6.tar.gz cd setuptools-25.1.6 python setup.py install
4.2下载安装pip
wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py sudo python ez_setup.py --insecure wget "https://pypi.python.org/packages/source/p/pip/pip-9.0.1.tar.gz" --no-check-certificate
解压安装
[root@master /usr/local/src]$ tar -zxxf pip-9.0.1.tar.gz [root@master /usr/local/src]$ cd pip-9.0.1 [root@master /usr/local/src]$ python setup.py install
这样就可以使用pip了
5.适用pip安装numpy、scipy
sudo pip install numpy sudo pip install scipy
sudo pip install matplotlib
6.python更新后, matplotlib.pyplot模块无法加载,通过百度,发现没有安装tk
yum -y install tk-devel
yum -y install tkinter
安装后python2.7依旧无法加载,更改文件
vim /usr/local/src/Python-2.7.10/Modules/Setup.dist
去掉这几行前边的“#”
_tkinter _tkinter.c tkappinit.c -DWITH_APPINIT -L/usr/local/lib -I/usr/local/include -ltk8.5 -ltcl8.5 -lX11
-ltk8.5 -ltcl8.5 默认是 8.2 ,请你系统实际tcl/tk版本修改
[root@master /usr/local/src/Python-2.7.10]$ rpm -qa | grep ^tk tkinter-2.6.6-66.el6_8.x86_64 tk-devel-8.5.7-5.el6.x86_64 tk-8.5.7-5.el6.x86_64 [root@master /usr/local/src/Python-2.7.10]$ rpm -qa | grep ^tcl tcl-8.5.7-6.el6.x86_64 tcl-devel-8.5.7-6.el6.x86_64
我系统中装的是8.5,所以这里我改成了8.5
然后保存退出
安装tck-devel、tk-devel
yum -y install tcl-devel tk-devel
新进入python2.7目录
执行
make make install