1. 程式人生 > >Centos7上安裝Python3

Centos7上安裝Python3

zip2 sql onf python2 openss qlite 命令 6.2 www.

安裝新的Python3與系統自帶的Python2共存

安裝依賴

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make

下載Python3並編譯安裝

下載Python3

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

可以使用迅雷下載再傳到服務器上

新建程序目錄

mkdir /usr/local/python3 

解壓並編譯安裝Python3

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

至此Python3和pip3已經安裝好

設置環境變量

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

此時使用python3命令就是執行python3,使用python命令就是執行自帶的python2,pip亦然

Centos7上安裝Python3