1. 程式人生 > >CentOS7編譯安裝Python3.6.3

CentOS7編譯安裝Python3.6.3

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 wget
  • 1

2、wget Python3.6.3;建立程式目錄;編譯安裝

# wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz
# mkdir -p /usr/local/python3
# tar -zxvf Python-3.6.3.tgz
# cd Python-3.6.3/ # ./configure --prefix=/usr/local/python3 && make && make install
  • 1
  • 2
  • 3
  • 4
  • 5

如無意外,則會安裝完成,如有意外,請自行度娘解決!!! 3、建立Python3的軟連結,並將/usr/local/python3/bin加入bash_profile

# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
# vim ~/.bash_profile
  • 1
  • 2
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs ##下面這句為新增內容 PATH=$PATH</span>:<span class="hljs-variable">$HOME/bin:/usr/local/python3/bin PATH=$PATH</span>:<span class="hljs-variable">$HOME/bin export PATH
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

然後

# source ~/.bash_profile
  • 1

檢視Python3.6.3 pip3是否正常

# python3 -V
Python 3.6.3
# pip3 -V
pip 9.0.1 from /usr/local/python3/lib/python3.6/site-packages (python 3.6)
  • 1
  • 2
  • 3
  • 4

至此,Python3.6.3安裝完畢,如出現其他錯誤可在評論區留言指出。