Centos上安裝Python3
阿新 • • 發佈:2018-11-11
1、檢視Python版本
[[email protected] ~]# python -V #注意,是大寫的V
Python 2.7.5
2、安裝Python可能需要依賴的庫
yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel
3、下載Python3的壓縮包。Python官網下載 https://www.python.org
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0b5.tgz
4、解壓縮Python壓縮包
[[email protected] ~]# tar -zxf Python-3.7.0b5.tgz [[email protected] ~]# cd Python-3.7.0b5 [[email protected] Python-3.7.0b5]# ls aclocal.m4 configure Grammar Lib Mac Modules PC pyconfig.h.in setup.py config.guess configure.ac Include LICENSE Makefile.pre.in Objects PCbuild Python Tools config.sub Doc install-sh m4 Misc Parser Programs README.rst
5、編譯安裝Python3.7
[[email protected] Python-3.7.0b5]# ./configure --prefix=/usr/local/ checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking for python3.7... no checking for python3... no checking for python... python checking for --enable-universalsdk... no checking for --with-universal-archs... no checking MACHDEP... checking for --without-gcc... no checking for --with-icc... no checking for gcc... no checking for cc... no checking for cl.exe... no configure: error: in `/root/Python-3.7.0b5': configure: error: no acceptable C compiler found in $PATH See `config.log' for more details
提示報錯,原因:缺少編譯器。解決方法:安裝gcc
[[email protected] Python-3.7.0b5]# yum install -y gcc
[[email protected] Python-3.7.0b5]# ./configure --prefix=/usr/local/
[[email protected] Python-3.7.0b5]# make
[[email protected]abbix93 Python-3.7.0b5]# make altinstall //此處不能用install安裝,因為install不區分版本,會出現多版本混亂的問題
6、更改Python預設連結
python3.7程式的執行檔案:/usr/local/bin/python3.7
python3.7應用程式目錄:/usr/local/lib/python3.7
pip7的執行檔案:/usr/local/bin/pip3.7
pyenv3的執行檔案:/usr/local/bin/pyenv-3.7
7、更改Python預設連結
cd/usr/bin
mv python python.backup
ln -s /usr/local/bin/python3.7 /usr/bin/python
ln -s /usr/local/bin/python3.7 /usr/bin/python3