Centos7安装Python2.7

1、删除现有Python
[root@test ~]# rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps ##强制删除已安装程序及其关联
[root@test ~]# whereis python |xargs rm -frv ##删除所有残余文件 ##xargs,允许你对输出执行其他某些命令
[root@test ~]# whereis python ##验证删除,返回无结果

2、删除现有的yum
[root@test ~]# rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps
[root@test ~]# whereis yum |xargs rm -frv

3、创建目录python和yum用以存放rpm包
#mkdir /software/python
#mkdir /software/yum

4、使用wget分别下载python以及yum的rpm包(注意:一定要和系统的版本号对应)
(1)下载python的rpm包:
#cd /software/python 进入目录
下载路径是:http://vault.centos.org/7.1.1503/os/x86_64/Packages//
(注意centos版本一定要正确,我的版本是7.1.1503)
下载的包有:
wget http://vault.centos.org/7.1.1503/os/x86_64/Packages/python-pycurl-7.19.0-17.el7.x86_64.rpm
wget http://vault.centos.org/7.1.1503/os/x86_64/Packages/python-devel-2.7.5-16.el7.x86_64.rpm
wget http://vault.centos.org/7.1.1503/os/x86_64/Packages/python-libs-2.7.5-16.el7.x86_64.rpm
wget http://vault.centos.org/7.1.1503/os/x86_64/Packages/python-urlgrabber-3.10-6.el7.noarch.rpm
wget http://vault.centos.org/7.1.1503/os/x86_64/Packages/rpm-python-4.11.1-25.el7.x86_64.rpm
(2)下载yum的rpm包:
#cd /software/yum
wget http://vault.centos.org/7.1.1503/os/x86_64/Packages/yum-3.4.3-125.el7.centos.noarch.rpm
wget http://vault.centos.org/7.1.1503/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://vault.centos.org/7.1.1503/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-29.el7.noarch.rpm

5、安装python以及yum的rpm包
(1)安装python:
#cd /software/python
#rpm -ivh python- rpm-python-

出现安装包的依赖问题,此时如下解决即可:
#rpm -ivh python- rpm-python- --nodeps --force
--nodeps --force为不考虑依赖包,强制安装。
安装完后即可运行python:

(2)安装yum:
#cd /software/yum
#rpm -ivh yum-*

至此yum重新安装成功!

6、安装pip
(1)首先安装epel扩展源:
#yum -y install epel-release

(2)更新完成之后,就可安装pip:
#yum -y install python-pip

(3)安装完成之后清除cache:
#yum clean all

(4)升级pip:
#python -m pip install --upgrade pip

7、安装所需要的库
(1)安装NumPy、SciPy、Matplotlib、pandas Statsmodels
#pip install numpy
#pip install scipy
#pip install matplotlib
#pip install pandas
#pip install statsmodels
(2)升级NumPy、SciPy、Matplotlib、pandas Statsmodels
#pip install --upgrade numpy scipy matplotlib pandas statsmodels

8、安装scikit-learn
#yum install python-tools
#pip install --upgrade python-tools
#pip install -U scikit-learn

9、验证安装是否成功
$python

import numpy as np
import scipy
import pandas as pd
import sklearn
import matplotlib.pyplot as plt
如果报错:

Traceback (most recent call last):
File "", line 1, in
File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py", line 115, in
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/init.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 6, in
from six.moves import tkinter as Tk
File "/usr/lib/python2.7/site-packages/six.py", line 203, in load_module
mod = mod._resolve()
File "/usr/lib/python2.7/site-packages/six.py", line 115, in _resolve
return _import_module(self.mod)
File "/usr/lib/python2.7/site-packages/six.py", line 82, in _import_module
import(name)
ImportError: No module named Tkinter
说明没有安装tkinter,使用如下命令安装:

$ sudo yum install tkinter
之后再测试就没问题了

import statsmodels

10、安装IPython
直接通过命令安装
#pip install ipython

转载于:https://blog.51cto.com/duanpeng/2331170

你可能感兴趣的:(Centos7安装Python2.7)