Centos7安装Python2.7

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

2、删除现有的yum
[[email protected] ~]# rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps
[[email protected] ~]# 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 "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py", line 115, in <module>
_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 <module>
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

原文地址:http://blog.51cto.com/duanpeng/2331170

时间: 2024-10-28 19:26:24

Centos7安装Python2.7的相关文章

centos7 安装python2.7.14 并与原版本共存

1. 前言 centos自带python2.6,由于yum指令是依赖python2.6的,为了确保yum的正常使用,千万不要升级python2.6或卸载python2.6,只需要安装python2.7,让它们俩共存就好,使用的时候用python2.7来加以区分. 首先切换到root用户,不用敲sudo:sudo su 2. 安装依赖库 yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readl

CentOS7安装python3.6保留python2.7

python3.6环境搭建 安装依赖 yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel gcc libffi-devel python-devel openssl-devel libcurl-dev libcurl-devel 获取tgz包(以3.6.4为

CentOS7 安装Firefly及测试

本文记录CentOS7安装Firefly的过程及遇到的错误 安装也可以同时参考社区提供的文章: http://www.9miao.com/forum.php?mod=viewthread&tid=33009&fromuid=87 没有安装mysql的请先参考这篇文章,快速安装: http://blog.csdn.net/alex_my/article/details/44711139 1 安装第三方库: easy_install twisted easy_install python-me

centos7 安装mysql--python模块出现EnvironmentError: mysql_config not found和error: command &#39;gcc&#39; failed with exit status 1

要想使python可以操作mysql 就需要MySQL-python驱动,它是python 操作mysql必不可少的模块. 下载地址:https://pypi.python.org/pypi/MySQL-python/ 下载MySQL-python-1.2.5.zip 文件之后直接解压.进入MySQL-python-1.2.5目录: python setup.py install 报错: [[email protected] MySQL-python-1.2.4]# python setup.p

在CentOS6,CentOS7安装 Let&#39;sEncrypt 免费SSL安全证书

相对来说,个人网站建立SSL是昂贵的,而且往往过程繁琐.一个标准的2048位证书费用至少150美元/年,网站除了要支付一笔昂贵的费用.重新配置Web服务器,并需要解决大量的配置错误.这让广大中小网站望而生畏. 然而,Let's Encrypt免费证书的开放,极大推进了国内 HTTPS 的进程.Let's Encrypt 真正的意义在于,它推动了 HTTPS 在小型网站和个人网站中的应用,加速全面 HTTPS 时代的到来.Let's Encrypt 的最大贡献是它的 ACME 协议,第一份全自动服

Cenos(6.6/7.1)下源码安装Python2.7、pip、MySQLdb、Django框架

Cenos7.1下安装Python.pip.MySQLdb.Django框架: 梳理下这几个的关系,centos6.5是redhat最新的社区版操作系统. Python2.7.5是开发语言(centos6.5下自带的python是2.6.6版本,所以需要源码更新,而centos7.1下面自带的是2.7.5) pip1.5.4是一个安装和管理 Python 包的工具 ,是easy_install的替代品,就像yum一样.用它可以安装指定版本的Django和mysql  Django是python下

Centos7 安装Python3.6.5 及 安装ipython 6.1.0

一.centos7 安装 Python3.6.5教程 1.在安装Python之前,需要先安装一些后面遇到的依赖问题(如果有依赖问题,按照提示安装): yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel     yum install xz gcc zlib 

centos7 安装pip+python3.6

centos7安装pip 1.执行:yum install python-pip 若没有python-pip包,先执行:yum -y install epel-release,再执行yum install python-pip 2.pip install --upgrade pip centos默认安装了python2.7 1.mkdir /usr/local/python3 2.安装依赖包: yum -y groupinstall "Development tools" yum -y

Centos7 安装Python3.7

# 更改yum源 cd /etc/yum.repos.d mv CentOS-Base.repo CentOS-Base.repo.bak wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo yum clean all yum makecache # 安装依赖.下载安装Python yum -y install zlib-devel bzip2-devel openssl-devel ncurses-deve