前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Centos7安装Python2.7

Centos7安装Python2.7

作者头像
py3study
发布2020-01-07 16:00:33
3.7K0
发布2020-01-07 16:00:33
举报
文章被收录于专栏:python3

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 "<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

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/09/19 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档