首先需要去網上下載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.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-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 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 "$-" 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安裝結束