Python官网:https://www.python.org/
一、查看CentOS版本和系统默认Python版本:
# cat /etc/redhat-release
# python -V
二、编译安装Python-3.6.1:
1、安装依赖软件包:
# yum -y groupinstall "Development tools"
# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-develreadline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
2、设置CentOS6当前系统时间:
# date 040413022017.30
# date
3、编译安装Python-3.6.1:
#wgethttps://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
# tar xf Python-3.6.1.tar.xz -C /usr/src
# cd /usr/src/Python-3.6.1
# ./configure --prefix=/usr/local/python3.6.1 --enable-shared --enable-profiling--enable-optimizations --disable-ipv6 --with-threads --with-pymalloc --with-fpectl--enable-loadable-sqlite-extensions
# make && make install //此步骤过程中需要执行测试,用时较长
4、更改CentOS6默认Python版本为3.6.1:
# mv /usr/bin/python /usr/bin/python2.6.6-old
# ln -s /usr/local/python3.6.1/bin/python3 /usr/bin/python
5、添加至PATH环境变量:
# vim /etc/profile.d/python3.6.1.sh
exportPATH=/usr/local/python3.6.1/bin:$PATH
# . /etc/profile.d/python3.6.1.sh
# echo $PATH
6、配置头文件:
# ln -sv /usr/local/python3.6.1/include /usr/include/python3.6
7、配置库文件:
# echo "/usr/local/python3.6.1/lib" >/etc/ld.so.conf.d/python3.6.1.conf
# cat /etc/ld.so.conf.d/python3.6.1.conf
# ldconfig
8、配置man帮助文档:
# vim /etc/man.config,新增如下代码:
MANPATH /usr/local/python3.6.1/share/man
9、查看配置后的Python版本:
# python3 -V
三、将yum中的版本修改为系统原来的2.6.6升级Python后会导致yum无法使用:
# vim /usr/bin/yum,将第一行的“#!/usr/bin/python”修改为“#!/usr/bin/python2.6.6-old”
首先安装epel扩展源:
#yum -y install epel-release
然后再安装pip
#yum -y install python-pip
centos查找命令
find/-name"pip*"
1、安装python3.6.1
2、安装setuptools35.0.2
3、安装pip
#easy_install pip
本文出自 “天道酬勤” 博客,请务必保留此出处http://qiuyue.blog.51cto.com/1246073/1912806
原文链接:https://www.f2er.com/centos/377728.html