CentOS7 Installing Python3
Posted Ooops
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS7 Installing Python3相关的知识,希望对你有一定的参考价值。
【我希望能在写博文的过程中提升英文,可能嘛?】
【Is it possible to improve my poor english by writting blog ? I don‘t know .】
最近开始学习python。
python火了这么久,我终于还是跪舔它了,我是一个跟风的人,学过C、C#、JAVA、PHP,无一例外的浅尝即止,不知道我这双已经近视的眼,确认过的眼神还对不对,希望python是我对的它。
顺便求大神们别再学了,我跟不上了。
I want to learn python from now on .
python is so popular that I cann‘t turn a blind eye and finally I put my knees to it . I am a following boy(maybe an uncle) , I have learned a lot of languages , such as C C++ JAVA PHP , none of them can be continued . I cann‘t be sure python is right for me , especially I am shortsighted , but I still hope python is my correct choice.
by the way , I begged all of the big-gods , stoped , I cann‘t catch up!
言归正传,CentOS7默认已经安装了python2.7的版本,而且yum命令及其他还用到它,所以我们不能删除系统默认安装的python。
那只有在系统中安装自己需要的版本(通常是更高更新的版本),并且和默认版本共存。
具体操作步骤,大概可分为以下几个:
1. 查看系统是否安装python,如有且版本不对,则备份;
2. 修改yum的配置文件;
3. 安装新版本python;
4. 修改python的软链接文件;
let‘s get back on track , CentOS7 had installed python2.7 by default , and yum command or others will use to it , so we cann‘t remove it .
so , we just have to install the right version of python what we want (usually more higher and more newer version),and with the default version at the same time in the system os.
as follows:
1. be sure the system has python or not ,if yes and the version isn‘t we want ,backup it ;
2. edit the configure file of yum command ;
3. install the new version python;
4. change the link files of python ;
一、查看是否已经安装了python(本机器为CentOS Linux release 7.5.1804,最小化安装)
1.使用python -V命令查看是否安装了python:
# python -V
Python 2.7.5
2.很明显是安装了python的2.7.5版本,这不是我所需要的,所以对这个版本进行备份:
# which python
/usr/bin/python
# cd /usr/bin
# ls -la python*
lrwxrwxrwx. 1 root root 7 Jun 20 15:14 python -> python2
lrwxrwxrwx. 1 root root 9 Jun 20 15:14 python2 -> python2.7
-rwxr-xr-x. 1 root root 7216 Apr 11 15:36 python2.7
3.可以看到系统的python命令实际上执行的是python2.7,我们备份下这个链接文件
# mv python python.bak
二、修改yum配置文件
1.查看yum文件
# ls -la /usr/bin/yum*
-rwxr-xr-x. 1 root root 801 Apr 13 20:58 /usr/bin/yum
2.查看urlgrabber文件
# ls -la /usr/libexec/urlgrabber-ext-down
-rwxr-xr-x. 1 root root 2603 Aug 26 2013 /usr/libexec/urlgrabber-ext-down
3.使用vim更改上述文件的文件头,把#!/usr/bin/python修改为#!/usr/bin/python2
# vim /usr/bin/yum
# vim /usr/libexec/urlgrabber-ext-down
三、安装新版本python
1.安装编译环境及可能使用到的依赖
# yum groupinstall "Development Tools"
# yum install -y ncurses-libs zlib-devel mysql-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
2.下载最新的版本(目前最新是3.6.5),下载地址:https://www.python.org/downloads/source
# wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz
3.编译安装
# tar -xvf Python-3.6.5.tar.xz
# cd Python-3.6.5
# ./configure --prefix=/usr/local/python3.6 --enable-optimizations
# make && make install
注:--prefix,安装路径;--enable-optimizations,优化选项,大概有10%的性能提升(网上说法,没验证)
四、修改软链接
1.创建系统软链接
# ln -s /usr/local/python3.6/bin/python3.6 /usr/bin/python
# ln -s /usr/local/python3.6/bin/pip3.6 /usr/bin/pip
2.查看
# python -V
# pip -V
文章到此结束。
Part 1. make sure it is had installed python.(my system is CentOS Linux release 7.5.1804 , minimal)
1.use command python -V to show python version:
# python -V
Python 2.7.5
2.obviously,there is installed python 2.7.5,so backup it:
# which python
/usr/bin/python
# cd /usr/bin
# ls -la python*
lrwxrwxrwx. 1 root root 7 Jun 20 15:14 python -> python2
lrwxrwxrwx. 1 root root 9 Jun 20 15:14 python2 -> python2.7
-rwxr-xr-x. 1 root root 7216 Apr 11 15:36 python2.7
3.we can see that system use python2.7,we can backup the link file
# mv python python.bak
Part 2. Edit yum config file
1.cat all yum files
# ls -la /usr/bin/yum*
-rwxr-xr-x. 1 root root 801 Apr 13 20:58 /usr/bin/yum
2.cat urlgrabber file
# ls -la /usr/libexec/urlgrabber-ext-down
-rwxr-xr-x. 1 root root 2603 Aug 26 2013 /usr/libexec/urlgrabber-ext-down
3.use vim modify the head of above files ,change #!/usr/bin/python to #!/usr/bin/python2
# vim /usr/bin/yum
# vim /usr/libexec/urlgrabber-ext-down
Part 3. Install new python version
1.Install compile environment and some possible dependences package
# yum groupinstall "Development Tools"
# yum install -y ncurses-libs zlib-devel mysql-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
2.download the newest version of python (the newest is 3.6.5),download url:https://www.python.org/downloads/source
# wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz
3.Installing
# tar -xvf Python-3.6.5.tar.xz
# cd Python-3.6.5
# ./configure --prefix=/usr/local/python3.6 --enable-optimizations
# make && make install
PS:--prefix,install path;--enable-optimizations,maybe optimization,about 10% performent improvement(this said by internet,no verification)
Part 4. create link files
1.create link files
# ln -s /usr/local/python3.6/bin/python3.6 /usr/bin/python
# ln -s /usr/local/python3.6/bin/pip3.6 /usr/bin/pip
2.make sure
# python -V
# pip -V
over.
以上是关于CentOS7 Installing Python3的主要内容,如果未能解决你的问题,请参考以下文章
centos7 + python 2.7 + pip + openvswitch 杂项问题
Installing Python 3.5.2 from source