centos python3安装

1、错误示范

  由于手欠,一上来就把python2给卸载的干干净净.....直接导致yum不可以用

# 强制删除已安装python及其关联
rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps
# 删除残余文件
whereis python|xargs rm -frv

2、补救措施

  彻底删除yum 防止干扰

#删除yum
rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps 
#删除残留文件
whereis yum |xargs rm -frv 
#验证删除完成,返回无结果
whereis yum 

  下载安装恢复

# 查看linux版本号,安装Python2.7的依赖包,就要找到Linux的版本号
cat /etc/redhat-release
# CentOS Linux release 7.2.1511 (Core) 
# 创建文件夹
mkdir /usr/local/src/python
mkdir /usr/local/src/yum
# 使用wget分别下载python以及yum的rpm包
# 进入python目录下
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-2.7.5-34.el7.x86_64.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-pycurl-7.19.0-17.el7.x86_64.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-devel-2.7.5-34.el7.x86_64.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-libs-2.7.5-34.el7.x86_64.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-urlgrabber-3.10-7.el7.noarch.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/rpm-python-4.11.3-17.el7.x86_64.rpm
# 进入yum目录下
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/yum-3.4.3-132.el7.centos.0.1.noarch.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-34.el7.noarch.rpm
# 安装python: --nodeps --force 不考虑依赖包,强制安装
rpm -ivh python-*   rpm-python-* --nodeps --force   
安装yum:
rpm -ivh yum-*
# 这里最好安装一下pip
yum install python-pip

3、python3安装

# yum更新yum源
yum update
# 安装Python 3.7所需的依赖否则安装后没有pip3包
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel libffi-devel gcc make
# 在官网下载所需版本,这里用的是3.7.0版本  淘宝镜像下就可以了
wget http://npm.taobao.org/mirrors/python/3.7.0/Python-3.7.0a2.tgz
# 解压
tar zxvf Python-3.7.0a2.tgz
# 创建安装目录
mkdir /usr/local/python3
# 编译安装
./configure --prefix=/usr/local/python3 
make && make install 
# 创建一下软连接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

4、blog搭建

我写这些东西都是因为我需要搭建一个blog环境:python3/mysql,这里遇见了很多坑,但都百度过了...下面就是执行程序,nginx代理一下就可以了,但这里重点记录一个脚本代码,我用第二行,因为博客日志对我没啥用:

# 日志指向一个文件
nohup python3 app.py > blog.log &
# nohup的日志直接指向黑洞
nohup python3 app.py > /dev/null 2>&1 &

Robin.Liu

三千大千世界,即非世界,是名世界

友情链接

苏ICP备18038860号

Copyright © sogemao.com 版权所有 Robin.Liu