centos7 安裝python3.7.1


centos7自帶python2,由於執行yum需要python2,所以即使安裝了python3也不能刪除python2
1.安裝依賴包
yum -y groupinstall "Development tools"

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 libffi-devel

2.下載自己需要的python版本,例如python3.7.1,下載要花費一段時間,要耐心等待

yum -y install wget
wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tar.xz

 

3.新建一個文件夾存放python3
mkdir /usr/local/python3 

 

4.把安裝包移動到該新建文件夾下,解壓安裝包,安裝python3,依次執行以下命令,花費時間較長,耐心等待

mv Python-3.7.1.tar.xz /usr/local/python3
tar -xvJf  Python-3.7.1.tar.xz
cd Python-3.7.1
./configure --prefix=/usr/local/python3
make  
make install

 

5.創建軟連接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

6.此時python3已經裝好,在命令行中輸入python3測試


7.修改yum配置文件,python2與python3共存
vi /usr/bin/yum

把#! /usr/bin/python修改為#! /usr/bin/python2(配置文件第一行)
同理
vi /usr/libexec/urlgrabber-ext-down

把文件里面的#! /usr/bin/python 也修改為#! /usr/bin/python2
此時完成python3安裝,且實現與python2共存,保持yum命令可用

下面是Ubuntu配置:

sudo apt-get install gcc

sudo apt-get install zlib1g-dev libbz2-dev libssl-dev libncurses5-dev libsqlite3-dev libreadline-dev tk-dev libgdbm-dev libdb-dev libpcap-dev xz-utils libexpat1-dev liblzma-dev libffi-dev libc6-dev

安裝好之后將一些文件開頭改成系統的python版本,避免沖突

vim /usr/lib/command-not-found

vim /usr/bin/gnome-terminal

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM