1. 安裝依賴環境
1
|
# 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
|
2.下載Python3
1
|
# wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
|
3.安裝python3
我個人習慣安裝在/usr/local/python3(具體安裝位置看個人喜好)
創建目錄:
1
|
# mkdir -p /usr/local/python3
|
解壓下載好的Python-3.x.x.tgz包(具體包名因你下載的Python具體版本不不同⽽而不不同,如:我下載的是Python3.6.1.那我這里就是Python-3.6.1.tgz)
1
|
# tar -zxvf Python-3.6.1.tgz
|
4.進入解壓後的目錄,編譯安裝。(編譯安裝前需要安裝編譯器yum install gcc)
1
2
|
# cd Python-3.6.1
# ./configure --prefix=/usr/local/python3 #/usr/local/python3爲安裝目錄
|
make
make install
1
|
make install 或者 make && make install
|
5.建立python3的軟鏈
1
|
# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
|
6.並將/usr/local/python3/bin加入PATH
1
2
3
4
5
6
7
8
9
|
# 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
|
按ESC,輸入:wq回車退出。
修改完記得執行行下面的命令,讓上一步的修改生效:
1
|
# source ~/.bash_profile
|
檢查Python3及pip3是否正常可用:
1
2
3
4
|
# python3 -V
Python 3.6 . 1
# pip3 -V
pip 9.0 . 1 from / usr / local / python3 / lib / python3. 6 / site - packages (python 3.6 )
|
7.不行的話嘗試創建一下pip3的軟鏈接
1
|
# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
|
https://www.cnblogs.com/fu-yong/p/9025489.html