Linux安裝python3.6
系統信息:
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.6.1810 (Core)
Release: 7.6.1810
Codename: Cor
安裝python3.6可能使用的依賴
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.6編譯安裝
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
tar -xzvf Python-3.6.5.tgz -C /tmp
進入目錄
cd /tmp/Python-3.6.5/
把Python3.6安裝到 /usr/local 目錄
./configure --prefix=/usr/local
我在安裝時出現如下異常:
[root@localhost cacti-spine-0.8.8h]# ./configure
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for gawk... (cached) gawk
checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in `/tmp/cacti-spine-0.8.8h':
configure: error: C compiler cannot create executables
See `config.log' for more details
原因:未安裝gcc
yum install gcc
編譯
make
make install
python3.6程序的執行文件:/usr/local/bin/python3.6
python3.6應用程序目錄:/usr/local/lib/python3.6
pip3的執行文件:/usr/local/bin/pip3.6
配置環境變量
更改/usr/bin/python鏈接
# 想要直接使用python
# 修改原軟連接
mv /usr/bin/python /usr/bin/python_bak
ln -s /usr/local/bin/python3.6 /usr/bin/python
ln -s /usr/local/bin/pip3.6 /usr/bin/pip
# python3調用
ln -s /usr/local/bin/python3.6 /usr/bin/python3
ln -s /usr/local/bin/pip3.6 /usr/bin/pip3
到這裏不要以爲安裝完成了,繼續看
你會發現你的yum命令不能用了。
因爲python指向python3了,所以要設置yum 直接調用python2。
vim /usr/libexec/urlgrabber-ext-down
vim /usr/bin/yum