下載并編譯
yum install -y readline-devel libffi-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel gcc openssl-devel
wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
tar -zxvf Python-3.6.1.tar.xz
cd Python-3.6
./configure --enable-shared --prefix=/usr/local CFLAGS=-fPIC LDFLAGS="-Wl,-rpath /usr/local/lib"
make -j24
make install
軟連接
自3.4版本起,setup_tools
及pip
工具自動(dòng)安裝,所以不用再手動(dòng)安裝了
sudo ln -sf /usr/local/bin/python3.6 /usr/bin/python3
sudo ln -sf /usr/local/bin/python3.6 /usr/bin/python3.6
sudo ln -sf /usr/local/bin/pip3.6 /usr/bin/pip3
sudo ln -sf /usr/local/bin/pip3.6 /usr/bin/pip3.6
錯(cuò)誤及解決
錯(cuò)誤1
[zhangxinming@localhost Python-3.6.1]$ sudo python3
python3: error while loading shared libraries: libpython3.6m.so.1.0: cannot open shared object file: No such file or directory
[zhangxinming@localhost Python-3.6.1]$ sudo pip3 install numpy
/usr/local/bin/python3.6: error while loading shared libraries: libpython3.6m.so.1.0: cannot open shared object file: No such file or directory
這兩類是一個(gè)錯(cuò)誤,因?yàn)閹觳辉趐yhon3這個(gè)程序可以正確連接的地方。有兩種解決方案麸折,一種是在./configure
加入LDFLAGS="-Wl,-rpath /usr/local/lib"
手動(dòng)指定,另一種是設(shè)定全局變量LD_LIBRARY_PATH
粘昨。顯然第一種方案更好一些垢啼,第二種方案導(dǎo)致普通用戶程序感染root程序的執(zhí)行,危害很大张肾。