linux-9qk9:/tmp/software_download # lsPython-3.6.4 gnureadline-6.3.8 libopenssl-devel-0.9.8j-2.1.x86_64.rpm zlib-devel-1.2.7-3.14.x86_64.rpmPython-3.6.4.tgz gnureadline-6.3.8.tar.gz setuptools-40.0.0.zip
linux-9qk9:/tmp/software_download # tar -zxvf Python-3.6.4.tgz linux-9qk9:/tmp/software_download # cd Python-3.6.4/随后需要去网上下载一些包,那么那些包是需要的呢,使用以下一个命令可以看到哪些包没有,用make的时候可以看到一堆包,那些标记skipped的没有,其中zlib,以及他的开发包zlib-devel, openssl,libopenssl-devel是必须的
--enable-optimizations可以检测需要的包, linux-9qk9:/tmp/software_download/Python-3.6.4 # ./configure --prefix=/usr/local/python3 --enable-optimizations 此处make时候就会检测那些包是否存在 linux-9qk9:/tmp/software_download/Python-3.6.4 # make0:14:48 load avg: 0.83 [389/406] test_winconsoleio0:14:48 load avg: 0.83 [390/406] test_winreg -- test_winconsoleio skipped0:14:49 load avg: 0.83 [391/406] test_winsound -- test_winreg skipped0:14:49 load avg: 0.83 [392/406] test_with -- test_winsound skipped (resource denied)0:14:49 load avg: 0.83 [393/406] test_wsgiref0:14:50 load avg: 0.83 [394/406] test_xdrlib0:14:50 load avg: 0.93 [395/406] test_xml_dom_minicompat0:14:51 load avg: 0.93 [396/406] test_xml_etree0:14:53 load avg: 0.93 [397/406] test_xml_etree_c0:14:56 load avg: 0.93 [398/406] test_xmlrpc0:14:59 load avg: 0.93 [399/406] test_xmlrpc_net0:15:00 load avg: 0.93 [400/406] test_yield_from -- test_xmlrpc_net skipped (resource denied)0:15:00 load avg: 0.94 [401/406] test_zipapp0:15:01 load avg: 0.94 [402/406] test_zipfile0:15:06 load avg: 0.94 [403/406] test_zipfile640:15:07 load avg: 0.94 [404/406] test_zipimport -- test_zipfile64 skipped (resource denied)0:15:07 load avg: 0.94 [405/406] test_zipimport_support0:15:09 load avg: 0.94 [406/406] test_zlibtest_zlib skipped 这里看到zlib有问题, 当然当中还有很多包是skipped的,自己认为有用的就去下载对应的包吧
linux-9qk9:/tmp/software_download/Python-3.6.4 # rpm -qi zlib Name : zlib Relocations: (not relocatable) Version : 1.2.7 Vendor: SUSE LINUX Products GmbH, Nuernberg, Germany Release : 0.10.128 Build Date: Sat May 11 10:11:54 2013 Install Date: Tue Jul 10 09:40:54 2018 Build Host: crick Group : System/Libraries Source RPM: zlib-1.2.7-0.10.128.src.rpm Size : 88752 License: zlib license. See http://zlib.net/zlib_license.html Signature : RSA/8, Sat May 11 10:11:57 2013, Key ID e3a5c360307e3d54 Packager : http://bugs.opensuse.org URL : http://www.zlib.net/ Summary : Data Compression Library Description : ftp://ds.internic.net/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). These documents are also available in other formats from ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html. Authors: -------- Rob Hooft <hooft@EMBL-Heidelberg.DE> Michael Mauldin <mlm@cs.cmu.edu> Distribution: SUSE Linux Enterprise 11 linux-9qk9:/tmp/software_download/Python-3.6.4 #
linux-9qk9:/tmp/software_download/Python-3.6.4 # rpm -qi zlib-develpackage zlib-devel is not installed
我们看到zlib-devel 没有安装,根据上面的版本信息我们去下载一个rpm包后面的release信息即0.10.128可以不一样
linux-9qk9:/tmp/software_download # lsPython-3.6.4 Python-3.6.4.tgz gnureadline-6.3.8.tar.gz setuptools-40.0.0.zip zlib-devel-1.2.7-3.14.x86_64.rpm
安装zlib-devel-1.2.7-3.14.x86_64.rpm
linux-9qk9:/tmp/software_download # rpm -ivh zlib-devel-1.2.7-3.14.x86_64.rpm warning: zlib-devel-1.2.7-3.14.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 19c4ef64Preparing... ########################################### [100%] 1:zlib-devel ########################################### [100%]linux-9qk9:/tmp/software_download #
安装libopenssl-devel, 这个有点类似centos里面的openssl-devel包
linux-9qk9:/tmp/software_download # rpm -qi opensslName : openssl Relocations: (not relocatable)Version : 0.9.8j Vendor: SUSE LINUX Products GmbH, Nuernberg, GermanyRelease : 0.50.1 Build Date: Mon Mar 25 11:10:09 2013Install Date: Tue Jul 10 09:41:57 2018 Build Host: acklinsGroup : Productivity/Networking/Security Source RPM: openssl-0.9.8j-0.50.1.src.rpmSize : 1182276 License: BSD 3-ClauseSignature : RSA/8, Mon Mar 25 11:10:24 2013, Key ID e3a5c360307e3d54Packager : http://bugs.opensuse.orgURL : http://www.openssl.org/Summary : Secure Sockets and Transport Layer SecurityDescription :The OpenSSL Project is a collaborative effort to develop a robust,commercial-grade, full-featured, and open source toolkit implementingthe Secure Sockets Layer (SSL v2/v3) and Transport Layer Security (TLSv1) protocols with full-strength cryptography. The project is managedby a worldwide community of volunteers that use the Internet tocommunicate, plan, and develop the OpenSSL toolkit and its relateddocumentation.
Derivation and License
OpenSSL is based on the excellent SSLeay library developed by Eric A.Young and Tim J. Hudson. The OpenSSL toolkit is licensed under anApache-style license, which basically means that you are free to get itand to use it for commercial and noncommercial purposes.
Please read the file /usr/share/doc/packages/openssl/README-FIPS.txtfor information on FIPS-140-2 compliant mode of operation of theopenssl shared libraries.
Authors:-------- Mark J. Cox <mark@openssl.org> Ralf S. Engelschall <rse@openssl.org> Dr. Stephen Henson <steve@openssl.org> Ben Laurie <ben@openssl.org> Bodo Moeller <bodo@openssl.org> Ulf Moeller <ulf@openssl.org> Holger Reif <holger@openssl.org> Paul C. Sutton <paul@openssl.org>Distribution: SUSE Linux Enterprise 11
linux-9qk9:/tmp/software_download # rpm -ivh libopenssl-devel-0.9.8j-2.1.x86_64.rpm warning: libopenssl-devel-0.9.8j-2.1.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 7af5fd64Preparing... ########################################### [100%] 1:libopenssl-devel ########################################### [100%]linux-9qk9:/tmp/software_download #
重新 make
linux-9qk9:/tmp/software_download # cd Python-3.6.4/linux-9qk9:/tmp/software_download/Python-3.6.4 # make
可以看到zlib-devel安装后就不报错了
0:15:34 load avg: 0.96 [403/406] test_zipfile640:15:35 load avg: 0.96 [404/406] test_zipimport -- test_zipfile64 skipped (resource denied)0:15:35 load avg: 0.96 [405/406] test_zipimport_support0:15:37 load avg: 0.96 [406/406] test_zlib
Total duration: 15 min 39 secTests result: FAILURE
随后正式安装make install,当然可以试试看zlib-devel不安装直接make install看看会报什么错误
linux-9qk9:/tmp/software_download/Python-3.6.4 # make install
Collecting setuptoolsCollecting pipInstalling collected packages: setuptools, pipSuccessfully installed pip-9.0.1 setuptools-28.8.0linux-9qk9:/tmp/software_download/Python-3.6.4 #
至此已经看到python3安装成功了,但是还有点擦屁股的事情要做
ps,如果安装了libopenssl-devel还是不行的话,我们就要去找一台已经import ssl不报错的机器比如下面那台机器,将_ssl.cpython-36m-x86_64-linux-gnu.so复制到/usr/local/python3/lib/python3.6/lib-dynload目录下面就可以了
inspect01:/usr/local/python3/lib/python3.6/lib-dynload # ls *ssl*_ssl.cpython-36m-x86_64-linux-gnu.so inspect01:/usr/local/python3/lib/python3.6/lib-dynload #
--------------------------------------------------------------------------------------------------------------------------
首先要在.proile或者.bash_profile里面添加环境变量,不然Python3无法直接访问
linux-9qk9:/tmp/software_download/Python-3.6.4 # python3If 'python3' is not a typo you can run the following command to lookup the package that contains the binary: command-not-found python3-bash: python3: command not found
我们新建立一个测试用户在测试用户里面添加环境变量
linux-9qk9:~ # useradd -m testlinux-9qk9:~ # ls /home/test/.bash_history .bashrc .emacs .fonts .gnu-emacs .inputrc .mozilla .muttrc .profile .vimrc .xim.template .xinitrc.template binlinux-9qk9:~ # su - testtest@linux-9qk9:~> view .profile
在.profile文件里面添加一行
PATH=$PATH:/usr/local/python3/bin
:wq! //保存退出命令
test@linux-9qk9:~> . .profile //激活新添加的PATH
输入python3可以看到已经可以启动python3了
test@linux-9qk9:~> python3Python 3.6.4 (default, Jul 11 2018, 01:24:13) [GCC 4.3.4 [gcc-4_3-branch revision 152973]] on linuxType "help", "copyright", "credits" or "license" for more information.Traceback (most recent call last): File "/etc/pythonstart", line 7, in <module> import readlineModuleNotFoundError: No module named 'readline'>>>
我们看到上面有个报错No module named 'readline',接下来我们来解决下
Traceback (most recent call last): File "/etc/pythonstart", line 7, in <module> import readlineModuleNotFoundError: No module named 'readline'>>> exit() //输入exit()退出Python3
test@linux-9qk9:~> su - //切换到rootPassword:
linux-9qk9:~ # cd /tmp/software_download/linux-9qk9:/tmp/software_download # lsPython-3.6.4 Python-3.6.4.tgz gnureadline-6.3.8.tar.gz setuptools-40.0.0.zip zlib-devel-1.2.7-3.14.x86_64.rpm
到https://pypi.org/下载 gnureadline-6.3.8.tar.gz,
千万不要下载readline-6.2.4.1.tar.gz ,这个包官方文档说了已经失效了,原话如下
WARNING: THIS PACKAGE IS DEPRECATED! It has been renamed to GNUREADLINE to resolve a name clash with the standard library module. The new PyPI page is here.
linux-9qk9:/tmp/software_download # tar -zxvf gnureadline-6.3.8.tar.gz
为root用户设置python3的PATH
linux-9qk9:~ # view /etc/profile
在最后一行添加 PATH=$PATH:/usr/local/python3/bin 随后wq!保存退出
401 case "$-" in402 *i*)403 if test "$TERM" = "xterm" -a -O "$tty" ; then404 if test -z "${SSH_TTY}" ; then405 test ! -f $HOME/.hushlogin -a -s /etc/motd && cat /etc/motd406 echo "Directory: $PWD"407 # Last but not least408 date409 fi410 #411 # shadow passwd412 # Note: on normal console this will be done by /bin/login413 #if test -r /var/log/faillog ; then414 # test -x /bin/faillog && /bin/faillog415 # test -x /usr/sbin/faillog && /usr/sbin/faillog416 #fi417 fi418 esac419 PATH=$PATH:/usr/local/python3/bin420 #421 # End of /etc/profile422 #
随后执行. /etc/profile使环境变量生效
linux-9qk9:/tmp/software_download # . /etc/profile
linux-9qk9:/tmp/software_download # linux-9qk9:/tmp/software_download # python3Python 3.6.4 (default, Jul 11 2018, 01:24:13) [GCC 4.3.4 [gcc-4_3-branch revision 152973]] on linuxType "help", "copyright", "credits" or "license" for more information.Traceback (most recent call last): File "/etc/pythonstart", line 7, in <module> import readlineModuleNotFoundError: No module named 'readline'>>> exit()linux-9qk9:/tmp/software_download #
执行python3 setup.py install进行安装
linux-9qk9:/tmp/software_download/gnureadline-6.3.8 # python3 setup.py install
安装完成后再次输入python3可以看到No module named 'readline'报错消失
linux-9qk9:/tmp/software_download/gnureadline-6.3.8 # python3Python 3.6.4 (default, Jul 11 2018, 01:24:13) [GCC 4.3.4 [gcc-4_3-branch revision 152973]] on linuxType "help", "copyright", "credits" or "license" for more information.>>>exit()
接下来我们搭建一个虚拟环境,网上有很多Python 虚拟环境 pyenv、venv(pyvenv)、virtualenv之间的区别 可以参考下 https://www.cnblogs.com/qinhan/p/9293126.html
由于我们使用的是3.6的Python版本,直接一条命令
test@linux-9qk9:~> python3 -m venv aa/bb //创建虚拟环境test@linux-9qk9:~> cd aa/bbtest@linux-9qk9:~/aa/bb> lsbin include lib lib64 pyvenv.cfg //可以看到虚拟环境创建成功test@linux-9qk9:~/aa/bb>
test@linux-9qk9:~/aa/bb> source bin/activate //激活虚拟环境(bb) test@linux-9qk9:~/aa/bb>
今后可以在虚拟环境下进行安装软件以及编译程序等,至此python3安装结束
转载于:https://www.cnblogs.com/qinhan/p/9293809.html
相关资源:SUSE Linux Enterprise Server 11 SP4 下载使用