CentOS7 安裝Python3.6.8

CentOS7 安裝Python3.6.8python

1. 安裝依賴環境sql

   yum -y groupinstall "Development tools"vim

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

 

二、下載Python3.6.8bash

新建個/usr/local/python3文件夾ui

mkdir /usr/local/python3

  
在python3文件夾下下載安裝包url

(/usr/local/python3 )spa

wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tar.xz

解壓文件code

tar -xvf Python-3.6.8.tar.xz

三、安裝Python3server

建立安裝文件的路徑sqlite

mkdir /usr/local/python3

四、編譯(在解壓的文件夾下 /usr/local/python3/python3.6.8)

./configure --prefix=/usr/local/python3

五、安裝(在解壓的文件夾下 /usr/local/python3/python3.6.8)

make make install # 先make再make install

六、建立新版本的軟連接

修改舊版本

mv /usr/bin/python /usr/bin/python_bak
mv /usr/bin/pip /usr/bin/pip_bak

建立新的軟鏈接  

ln -s /usr/local/python3/bin/python3 /usr/bin/python
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip

檢查python的版本

python -V

七、配置成功後,pip3用不了,須要進一步配置

將/usr/local/python3/bin加入PATH

vim ~/.bash_profile

修改後以下: 
.bash_profile

#Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin:/usr/local/python3/bin export PATH

複製代碼 
保存退出後,執行如下命令,讓上一步修改爲功

source ~/.bash_profile 
完成!

不過,因爲yum是py2寫的,因此更換完python路徑後,yum可能會出現錯誤 
因此要修改配置文件

vim /usr/bin/yum
vim /usr/libexec/urlgrabber-ext-down

把第一行python改成python2

相關文章
相關標籤/搜索