在Centos上安裝Python3
一、安裝依賴環境
輸入命令: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
1.進入opt檔案目錄下,cd opt/
2.下載python3
輸入命令 wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz
如果出現 找不到wget命令,輸入yum -y install wget,安裝其依賴將會被安裝
3.安裝Python3
安裝在/usr/local/python3(具體安裝位置看個人喜好)
(1)建立目錄: mkdir -p /usr/local/python3
(2)解壓下載好的Python-3.x.x.tgz包(具體包名因你下載的Python具體版本不不同⽽而不不同,如:我下載的是Python3.7.1.那我這里就是Python-3.7.1.tgz)
輸入命令 tar -zxvf Python-3.7.1.tgz
解壓後出現python的資料夾
4.進入解壓後的目錄,編譯安裝。(編譯安裝前需要安裝編譯器yum install gcc)
(1)安裝gcc
輸入命令 yum install gcc,確認下載安裝輸入“y”
(2)3.7版本之後需要一個新的包libffi-devel
安裝即可:yum install libffi-devel -y
(3)進入python資料夾,生成編譯指令碼(指定安裝目錄):
cd Python-3.7.1
./configure --prefix=/usr/local/python3
#/usr/local/python3為上面步驟建立的目錄
(4)編譯:make
(5)編譯成功後,編譯安裝:make install
安裝成功:
(6)檢查python3.7的編譯器:/usr/local/python3/bin/python3.7
5.建立Python3和pip3的軟鏈:
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
6.並將/usr/local/python3/bin加入PATH
(1)vim /etc/profile
(2)按“I”,然後貼上下面內容:
# 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
(3)按ESC,輸入:wq回車退出。
(4)修改完記得執行行下面的命令,讓上一步的修改生效:
source ~/.bash_profile
7.檢查Python3及pip3是否正常可用:
python3 -V
pip3 -V
一、安裝依賴環境
輸入命令: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
1.進入opt檔案目錄下,cd opt/
2.下載python3
輸入命令 wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz
如果出現 找不到wget命令,輸入yum -y install wget,安裝其依賴將會被安裝
3.安裝Python3
安裝在/usr/local/python3(具體安裝位置看個人喜好)
(1)建立目錄: mkdir -p /usr/local/python3
(2)解壓下載好的Python-3.x.x.tgz包(具體包名因你下載的Python具體版本不不同⽽而不不同,如:我下載的是Python3.7.1.那我這里就是Python-3.7.1.tgz)
輸入命令 tar -zxvf Python-3.7.1.tgz
解壓後出現python的資料夾
4.進入解壓後的目錄,編譯安裝。(編譯安裝前需要安裝編譯器yum install gcc)
(1)安裝gcc
輸入命令 yum install gcc,確認下載安裝輸入“y”
(2)3.7版本之後需要一個新的包libffi-devel
安裝即可:yum install libffi-devel -y
(3)進入python資料夾,生成編譯指令碼(指定安裝目錄):
cd Python-3.7.1
./configure --prefix=/usr/local/python3
#/usr/local/python3為上面步驟建立的目錄
(4)編譯:make
(5)編譯成功後,編譯安裝:make install
安裝成功:
(6)檢查python3.7的編譯器:/usr/local/python3/bin/python3.7
5.建立Python3和pip3的軟鏈:
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
6.並將/usr/local/python3/bin加入PATH
(1)vim /etc/profile
(2)按“I”,然後貼上下面內容:
# 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
(3)按ESC,輸入:wq回車退出。
(4)修改完記得執行行下面的命令,讓上一步的修改生效:
source ~/.bash_profile
7.檢查Python3及pip3是否正常可用:
python3 -V
pip3 -V