centOS7環境下安裝Python3(2018.06)
阿新 • • 發佈:2019-01-27
centos7已經自帶了Python2.7環境,但是不能解除安裝了,因為系統很多命令用的這個環境
,通過which python可以知道安裝的位置
[root@master Python-3.6.2]# python
Python 2.7.5 (default, Nov 6 2016, 00:28:07)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
[root@master Python-3.6.2]# which python
/usr/bin/python
安裝Python3環境
執行下面兩個命令:
# 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
wget https://www.python .org/ftp/python/3.6.2/Python-3.6.2.tar.xz
建立一個Python3的資料夾
# mkdir /usr/local/python3
解壓剛剛下載的檔案,進入解壓後的資料夾,再繼續操作
# tar -xvJf Python-3.6.2.tar.xz
# cd Python-3.6.2
# ./configure --prefix=/usr/local/python3
# make
# make install
如果make命令沒有安裝的可以執行下面安裝一下,在執行上面步驟
#yum install make
#yum install cmake
#yum install cmake
make install命令執行完後,/usr/local/python3會有檔案,最後建立軟連結
# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
最後輸入python3測試是否已安裝成功
[root@master Python-3.6.2]# python3
Python 3.6.2 (default, Jun 27 2018, 17:07:22)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
[root@master Python-3.6.2]#