下载并编译
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
工具自动安装,所以不用再手动安装了
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
错误及解决
错误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
这两类是一个错误,因为库不在pyhon3这个程序可以正确连接的地方。有两种解决方案,一种是在./configure
加入LDFLAGS="-Wl,-rpath /usr/local/lib"
手动指定,另一种是设定全局变量LD_LIBRARY_PATH
。显然第一种方案更好一些,第二种方案导致普通用户程序感染root程序的执行,危害很大。