参考了文章:Python 环境搭建 : http://www.runoob.com/python/python-install.html
参考了文章:Python 安装 zlib 模块:http://blog.csdn.net/wbiblem/article/details/72598245
参考了文章:python3.6 安装后没有 pip?https://www.zhihu.com/question/54906859
需要安装zlib-1.2.8.tar.gz
安装zlib模块
#下载地址http://www.zlib.net/
tar xzvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
make
make install
#zlib 安装完后,libz.a 在 /usr/local/lib/,zlib.h 文件在 /usr/include
#(opensuse 中 zlib.h 默认放在 /usr/local/include/中)
编译安装
tar -xzvf Python-3.6.4.tgz
cd Python-3.6.4
#./configure --prefix=/usr/local/Python-3.6.4
./configure --prefix=/usr/local/Python-3.6.4 --with-zlib=/usr/include
make clean
make
make install
修改 Python 软链
mv /usr/bin/python /usr/bin/python2.6 #根据需要来
cp /usr/bin/python2.6 /usr/bin/python2.6.bak #根据需要来
#mv /usr/bin/python2.6.bak /usr/bin/python2.6
ln -sf /usr/local/Python-3.6.4/bin/python3.6 /usr/bin/python
ln -s /usr/local/Python-3.6.4/bin/python3.6 /usr/bin/python3
配置用户变量
export PATH="$PATH:/usr/local/Python-3.6.4/bin"
#export PATH="$PATH:/usr/local/bin/python"
/usr/local/Python-3.6.4/bin
python3.6 安装后没有 pip?
#https://www.zhihu.com/question/54906859
python -m ensurepip
#pip is bundled with Python > 3.4
#On Unix-like systems use:
#python3.6 -m pip install [Package_to_install]
#python -m pip help install
-----------------------update 2018年3月13日------------------------------------
今天发现还有一些常用模块不能用,编译发现如下提示:下面的模块都缺少相关的依赖包而安装不了!
Python build finished successfully!
The necessary bits to build these optional modules were not found:
_bz2 _curses _curses_panel
_dbm _gdbm _lzma
_sqlite3 _tkinter readline
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
以下安装相关的模块
安装可能需要的模块
zypper in $( zypper se python*| grep -v 源代码包 | grep -v ^i | grep python | awk '{print $2}' )
安装zypper se bz2的模块
#下载地址http://www.bzip.org/downloads.html
tar -xzvf bzip2-1.0.6.tar.gz
cd bzip2-1.0.6
#为编译做准备,创建 libbz2.so 动态链接库 (这一步很重要,安装 python 的时候如果没有这一步,python 安装不上 bz2 模块)
make -f Makefile-libbz2_so
make && make install
安装zypper se sqlite3的模块
#下载地址http://www.sqlite.org/2014/sqlite-autoconf-3080600.tar.gz
./configure --prefix=/usr/local
make && make install
安装模块zypper se readline
#下载 readline https://ftp.gnu.org/gnu/readline/readline-7.0.tar.gz
./configure
make && make install
安装模块 zypper se ssl
#下载 https://www.openssl.org/source/openssl-1.0.2n.tar.gz
./config
make && make install
安装模块 zypper se tkinter [失败]
#下载 tkinter https://iweb.dl.sourceforge.net/project/tcl/Tcl/8.6.8/tk8.6.8-src.tar.gz
#下载 tkinter https://prdownloads.sourceforge.net/tcl/tcl8.6.8-src.tar.gz
#下载 tkinter http://ftp.gwdg.de/pub/opensuse/distribution/leap/42.3/repo/oss/suse/x86_64/python3-tk-3.4.6-11.1.x86_64.rpm
rpm -q tcl && rpm -q tk
cd /root/install/tcl8.6.8/unix
./configure
make && make install
#安装zypper se lzma的模块
#LZMA comes as part of the XZ open source compression library.
#https://tukaani.org/xz/xz-5.2.3.tar.gz
#find /usr /opt -name "lzma.h" -print
./configure
make && make install
rpm -ivh python3-tk-3.4.6-11.1.x86_64.rpm --nodeps
使用上面的方案安装模块之后,还有这个_tkinter一直找不到安装的方法,同时还有_hashlib _ssl二个模块安装失败。
Python build finished successfully!
The necessary bits to build these optional modules were not found:
_tkinter
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
Failed to build these modules:
_hashlib _ssl
先到这里了,发现Python的环境大都是contos,找SUSE的资料都找不多到,少得可怜。