suse11 安装 python3.6 python3 安装步骤

时间:2023-11-01 17:20:08
首先需要去网上下载Python-3.6.4.tgz,libopenssl-devel-0.9.8j-2.1.x86_64.rpm zlib-devel-1.2.7-3.14.x86_64.rpm

linux-9qk9:/tmp/software_download # ls
Python-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.rpm
Python-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 # make                                                            

0:14:48 load avg: 0.83 [389/406] test_winconsoleio
0:14:48 load avg: 0.83 [390/406] test_winreg -- test_winconsoleio skipped
0:14:49 load avg: 0.83 [391/406] test_winsound -- test_winreg skipped
0: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_wsgiref
0:14:50 load avg: 0.83 [394/406] test_xdrlib
0:14:50 load avg: 0.93 [395/406] test_xml_dom_minicompat
0:14:51 load avg: 0.93 [396/406] test_xml_etree
0:14:53 load avg: 0.93 [397/406] test_xml_etree_c
0:14:56 load avg: 0.93 [398/406] test_xmlrpc
0:14:59 load avg: 0.93 [399/406] test_xmlrpc_net
0: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_zipapp
0:15:01 load avg: 0.94 [402/406] test_zipfile
0:15:06 load avg: 0.94 [403/406] test_zipfile64
0: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_support
0:15:09 load avg: 0.94 [406/406] test_zlib
test_zlib skipped   这里看到zlib有问题, 当然当中还有很多包是skipped的,自己认为有用的就去下载对应的包吧

linux-9qk9:/tmp/software_download/Python-3.6. # 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 ::
Install Date: Tue Jul :: Build Host: crick
Group : System/Libraries Source RPM: zlib-1.2.-0.10..src.rpm
Size : License: zlib license. See http://zlib.net/zlib_license.html
Signature : RSA/, Sat May :: , 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
linux-9qk9:/tmp/software_download/Python-3.6. #

linux-9qk9:/tmp/software_download/Python-3.6.4 # rpm -qi zlib-devel
package zlib-devel is not installed

我们看到zlib-devel 没有安装,根据上面的版本信息我们去下载一个rpm包后面的release信息即0.10.128可以不一样

linux-9qk9:/tmp/software_download # ls
Python-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 19c4ef64
Preparing... ########################################### [100%]
1:zlib-devel ########################################### [100%]
linux-9qk9:/tmp/software_download #

安装libopenssl-devel, 这个有点类似centos里面的openssl-devel包

linux-9qk9:/tmp/software_download # rpm -qi openssl
Name : openssl Relocations: (not relocatable)
Version : 0.9.8j Vendor: SUSE LINUX Products GmbH, Nuernberg, Germany
Release : 0.50.1 Build Date: Mon Mar 25 11:10:09 2013
Install Date: Tue Jul 10 09:41:57 2018 Build Host: acklins
Group : Productivity/Networking/Security Source RPM: openssl-0.9.8j-0.50.1.src.rpm
Size : 1182276 License: BSD 3-Clause
Signature : RSA/8, Mon Mar 25 11:10:24 2013, Key ID e3a5c360307e3d54
Packager : http://bugs.opensuse.org
URL : http://www.openssl.org/
Summary : Secure Sockets and Transport Layer Security
Description :
The OpenSSL Project is a collaborative effort to develop a robust,
commercial-grade, full-featured, and open source toolkit implementing
the Secure Sockets Layer (SSL v2/v3) and Transport Layer Security (TLS
v1) protocols with full-strength cryptography. The project is managed
by a worldwide community of volunteers that use the Internet to
communicate, plan, and develop the OpenSSL toolkit and its related
documentation.

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 an
Apache-style license, which basically means that you are free to get it
and to use it for commercial and noncommercial purposes.

Please read the file /usr/share/doc/packages/openssl/README-FIPS.txt
for information on FIPS-140-2 compliant mode of operation of the
openssl 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 7af5fd64
Preparing... ########################################### [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_zipfile64
0: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_support
0:15:37 load avg: 0.96 [406/406] test_zlib

Total duration: 15 min 39 sec
Tests result: FAILURE

随后正式安装make install,当然可以试试看zlib-devel不安装直接make install看看会报什么错误

linux-9qk9:/tmp/software_download/Python-3.6.4 # make install

Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-9.0.1 setuptools-28.8.0
linux-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 # python3
If '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 test
linux-9qk9:~ # ls /home/test/
.bash_history .bashrc .emacs .fonts .gnu-emacs .inputrc .mozilla .muttrc .profile .vimrc .xim.template .xinitrc.template bin
linux-9qk9:~ # su - test
test@linux-9qk9:~> view .profile

在.profile文件里面添加一行

PATH=$PATH:/usr/local/python3/bin

:wq!  //保存退出命令

test@linux-9qk9:~> . .profile //激活新添加的PATH

输入python3可以看到已经可以启动python3了

test@linux-9qk9:~> python3
Python 3.6.4 (default, Jul 11 2018, 01:24:13)
[GCC 4.3.4 [gcc-4_3-branch revision 152973]] on linux
Type "help", "copyright", "credits" or "license" for more information.
Traceback (most recent call last):
File "/etc/pythonstart", line 7, in <module>
import readline
ModuleNotFoundError: No module named 'readline'
>>>

我们看到上面有个报错No module named 'readline',接下来我们来解决下

Traceback (most recent call last):
File "/etc/pythonstart", line 7, in <module>
import readline
ModuleNotFoundError: No module named 'readline'
>>> exit()    //输入exit()退出Python3

test@linux-9qk9:~> su -   //切换到root
Password:

linux-9qk9:~ # cd /tmp/software_download/
linux-9qk9:/tmp/software_download # ls
Python-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 * 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 "$-" in
402 *i*)
403 if test "$TERM" = "xterm" -a -O "$tty" ; then
404 if test -z "${SSH_TTY}" ; then
405 test ! -f $HOME/.hushlogin -a -s /etc/motd && cat /etc/motd
406 echo "Directory: $PWD"
407 # Last but not least
408 date
409 fi
410 #
411 # shadow passwd
412 # Note: on normal console this will be done by /bin/login
413 #if test -r /var/log/faillog ; then
414 # test -x /bin/faillog && /bin/faillog
415 # test -x /usr/sbin/faillog && /usr/sbin/faillog
416 #fi
417 fi
418 esac
419 PATH=$PATH:/usr/local/python3/bin
420 #
421 # End of /etc/profile
422 #

 

随后执行. /etc/profile使环境变量生效

linux-9qk9:/tmp/software_download # . /etc/profile

linux-9qk9:/tmp/software_download #
linux-9qk9:/tmp/software_download # python3
Python 3.6.4 (default, Jul 11 2018, 01:24:13)
[GCC 4.3.4 [gcc-4_3-branch revision 152973]] on linux
Type "help", "copyright", "credits" or "license" for more information.
Traceback (most recent call last):
File "/etc/pythonstart", line 7, in <module>
import readline
ModuleNotFoundError: 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 # python3
Python 3.6.4 (default, Jul 11 2018, 01:24:13)
[GCC 4.3.4 [gcc-4_3-branch revision 152973]] on linux
Type "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/bb
test@linux-9qk9:~/aa/bb> ls
bin 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安装结束