首先去python官網下載python3的源碼包,網址:https://www.python.org/
或者直接wget下載
wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz
#安裝python時可能需要依賴包,安裝之前最好先安裝一下下面的依賴包,網上找到兩條命令如下:
[root@qinhan bin]# yum -y install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
沒有網絡的話,哥教你怎么手動安裝,有網絡可以用yum pip安裝的話可以不看
------------------------------------------------zlib 安裝開始-------------------------------------------------------------------------------------- 下載zlib1.2.11 http://www.zlib.net/ 我下載的是1.2.11版本 ./configure --prefix=/usr/local/zlib1_2_11 make make install ------------------------------------------------zlib 安裝結束--------------------------------------------------------------------------------------
------------------------------------------------zlib devel 安裝開始--------------------------------------------------------------------------------------
http://rpmfind.net/linux/rpm2html/search.php?query=zlib-devel
------------------------------------------------zlib devel 安裝開始--------------------------------------------------------------------------------------
zlib-devel包可以到以下連接查找,那么如何找到對應的版本呢我們使用rpm -qi zlib 可以找到對應的版本信息,隨后zlib-devel rpm只要根據版本信息去找就可以了,接下來所有的rpm包安裝方法參考zlib
http://rpmfind.net/linux/rpm2html/search.php?query=zlib-devel
[root@localhost software_download]# rpm -qi zlib
Name : zlib
Version : 1.2.7
Release : 17.el7
Architecture: x86_64
Install Date: 2018年03月13日 星期二 18時53分26秒
Group : System Environment/Libraries
Size : 185710
License : zlib and Boost
Signature : RSA/SHA256, 2016年11月21日 星期一 05時05分07秒, Key ID 24c6a8a7f4a80eb5
Source RPM : zlib-1.2.7-17.el7.src.rpm
Build Date : 2016年11月06日 星期日 02時09分15秒
Build Host : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : http://www.zlib.net/
Summary : The compression and decompression library
Description :
Zlib is a general-purpose, patent-free, lossless data compression
library which is used by many different programs.
隨后根據版本包找到對應的rpm包
[root@localhost software_download]# ls
zlib-1.2.11 zlib-1.2.11.tar.gz zlib-devel-1.2.7-17.el7.x86_64.rpm
執行rpm -ivh zlib-devel-1.2.7-17.el7.x86_64.rpm 安裝
root@localhost software_download]# rpm -ivh zlib-devel-1.2.7-17.el7.x86_64.rpm
警告:zlib-devel-1.2.7-17.el7.x86_64.rpm: 頭V3 RSA/SHA256 Signature, 密鑰 ID f4a80eb5: NOKEY
准備中... ################################# [100%]
正在升級/安裝...
1:zlib-devel-1.2.7-17.el7 ################################# [100%]
------------------------------------------------zlib devel 安裝結束--------------------------------------------------------------------------------------
------------------------------------------------bzip2 devel 安裝開始--------------------------------------------------------------------------------------
bzip 系統已經安裝了,如果沒安裝,請自行百度
[root@localhost software_download]# rpm -qi bzip2
Name : bzip2
Version : 1.0.6
Release : 13.el7
Architecture: x86_64
Install Date: 2018年03月13日 星期二 18時54分02秒
Group : Applications/File
Size : 83791
License : BSD
Signature : RSA/SHA256, 2015年11月25日 星期三 22時18分37秒, Key ID 24c6a8a7f4a80eb5
Source RPM : bzip2-1.0.6-13.el7.src.rpm
Build Date : 2015年11月20日 星期五 13時04分52秒
Build Host : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : http://www.bzip.org/
Summary : A file compression utility
Description :
Bzip2 is a freely available, patent-free, high quality data compressor.
Bzip2 compresses files to within 10 to 15 percent of the capabilities
of the best techniques available. However, bzip2 has the added benefit
of being approximately two times faster at compression and six times
faster at decompression than those techniques. Bzip2 is not the
fastest compression utility, but it does strike a balance between speed
and compression capability.
Install bzip2 if you need a compression utility.
[root@localhost software_download]# rpm -ivh bzip2-devel-1.0.6-13.el7.x86_64.rpm
警告:bzip2-devel-1.0.6-13.el7.x86_64.rpm: 頭V3 RSA/SHA256 Signature, 密鑰 ID f4a80eb5: NOKEY
准備中... ################################# [100%]
正在升級/安裝...
1:bzip2-devel-1.0.6-13.el7 ################################# [100%]
[root@localhost software_download]#
------------------------------------------------bzip2 devel 安裝結束--------------------------------------------------------------------------------------
------------------------------------------------openssl devel 安裝開始--------------------------------------------------------------------------------------
openssl已經安裝
[root@localhost software_download]# rpm -qi openssl
Name : openssl
Epoch : 1
Version : 1.0.1e
Release : 60.el7
Architecture: x86_64
Install Date: 2018年03月13日 星期二 18時54分55秒
Group : System Environment/Libraries
Size : 1611673
License : OpenSSL
Signature : RSA/SHA256, 2016年11月21日 星期一 03時48分52秒, Key ID 24c6a8a7f4a80eb5
Source RPM : openssl-1.0.1e-60.el7.src.rpm
Build Date : 2016年11月06日 星期日 11時49分26秒
Build Host : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : http://www.openssl.org/
Summary : Utilities from the general purpose cryptography library with TLS implementation
Description :
The OpenSSL toolkit provides support for secure communications between
machines. OpenSSL includes a certificate management tool and shared
libraries which provide various cryptographic algorithms and
protocols.
這個openssl-devel比較麻煩,用Yum看了下需要各種更新,先不裝
依賴關系解決
====================================================================================================================================================
Package 架構 版本 源 大小
====================================================================================================================================================
正在安裝:
openssl-devel x86_64 1:1.0.2k-12.el7 base 1.5 M
為依賴而安裝:
keyutils-libs-devel x86_64 1.5.8-3.el7 base 37 k
krb5-devel x86_64 1.15.1-19.el7 updates 269 k
libcom_err-devel x86_64 1.42.9-12.el7_5 updates 31 k
libselinux-devel x86_64 2.5-12.el7 base 186 k
libsepol-devel x86_64 2.5-8.1.el7 base 77 k
libverto-devel x86_64 0.2.5-4.el7 base 12 k
pcre-devel x86_64 8.32-17.el7 base 480 k
為依賴而更新:
e2fsprogs x86_64 1.42.9-12.el7_5 updates 699 k
e2fsprogs-libs x86_64 1.42.9-12.el7_5 updates 167 k
krb5-libs x86_64 1.15.1-19.el7 updates 747 k
krb5-workstation x86_64 1.15.1-19.el7 updates 814 k
libcom_err x86_64 1.42.9-12.el7_5 updates 41 k
libkadm5 x86_64 1.15.1-19.el7 updates 175 k
libselinux x86_64 2.5-12.el7 base 162 k
libselinux-python x86_64 2.5-12.el7 base 235 k
libselinux-utils x86_64 2.5-12.el7 base 151 k
libsepol x86_64 2.5-8.1.el7 base 297 k
libss x86_64 1.42.9-12.el7_5 updates 45 k
openssl x86_64 1:1.0.2k-12.el7 base 492 k
openssl-libs x86_64 1:1.0.2k-12.el7 base 1.2 M
pcre x86_64 8.32-17.el7 base 422 k
事務概要
====================================================================================================================================================
安裝 1 軟件包 (+ 7 依賴軟件包)
升級 ( 14 依賴軟件包)
------------------------------------------------openssl devel 安裝結束--------------------------------------------------------------------------------------
------------------------------------------------ncurses devel 安裝開始--------------------------------------------------------------------------------------
[root@localhost software_download]# rpm -qi ncurses
Name : ncurses
Version : 5.9
Release : 14.20130511.el7_4
Architecture: x86_64
Install Date: 2018年07月05日 星期四 11時52分01秒
Group : System Environment/Base
Size : 439378
License : MIT
Signature : RSA/SHA256, 2017年09月07日 星期四 20時43分11秒, Key ID 24c6a8a7f4a80eb5
Source RPM : ncurses-5.9-14.20130511.el7_4.src.rpm
Build Date : 2017年09月07日 星期四 06時08分29秒
Build Host : c1bm.rdu2.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : http://invisible-island.net/ncurses/ncurses.html
Summary : Ncurses support utilities
Description :
The curses library routines are a terminal-independent method of
updating character screens with reasonable optimization. The ncurses
(new curses) library is a freely distributable replacement for the
discontinued 4.4 BSD classic curses library.
This package contains support utilities, including a terminfo compiler
tic, a decompiler infocmp, clear, tput, tset, and a termcap conversion
tool captoinfo.
[root@localhost software_download]# rpm -ivh ncurses-devel-5.9-14.20130511.el7_4.x86_64.rpm
准備中... ################################# [100%]
正在升級/安裝...
1:ncurses-devel-5.9-14.20130511.el7################################# [100%]
[root@localhost software_download]#
------------------------------------------------ncurses devel 安裝結束--------------------------------------------------------------------------------------
------------------------------------------------sqlite devel 安裝開始--------------------------------------------------------------------------------------
[root@localhost software_download]# rpm -qi sqlite
Name : sqlite
Version : 3.7.17
Release : 8.el7
Architecture: x86_64
Install Date: 2018年03月13日 星期二 18時53分31秒
Group : Applications/Databases
Size : 814231
License : Public Domain
Signature : RSA/SHA256, 2015年11月25日 星期三 23時40分39秒, Key ID 24c6a8a7f4a80eb5
Source RPM : sqlite-3.7.17-8.el7.src.rpm
Build Date : 2015年11月20日 星期五 16時45分59秒
Build Host : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : http://www.sqlite.org/
Summary : Library that implements an embeddable SQL database engine
Description :
SQLite is a C library that implements an SQL database engine. A large
subset of SQL92 is supported. A complete database is stored in a
single disk file. The API is designed for convenience and ease of use.
Applications that link against SQLite can enjoy the power and
flexibility of an SQL database without the administrative hassles of
supporting a separate database server. Version 2 and version 3 binaries
are named to permit each to be installed on a single host
[root@localhost software_download]# rpm -ivh sqlite-devel-3.7.17-8.el7.x86_64.rpm
警告:sqlite-devel-3.7.17-8.el7.x86_64.rpm: 頭V3 RSA/SHA256 Signature, 密鑰 ID f4a80eb5: NOKEY
准備中... ################################# [100%]
正在升級/安裝...
1:sqlite-devel-3.7.17-8.el7 ################################# [100%]
------------------------------------------------sqlite devel 安裝結束--------------------------------------------------------------------------------------
------------------------------------------------readline devel 安裝開始--------------------------------------------------------------------------------------
[root@localhost software_download]# rpm -qi readline
Name : readline
Version : 6.2
Release : 9.el7
Architecture: x86_64
Install Date: 2018年03月13日 星期二 18時53分31秒
Group : System Environment/Libraries
Size : 460408
License : GPLv3+
Signature : RSA/SHA256, 2014年07月04日 星期五 12時47分34秒, Key ID 24c6a8a7f4a80eb5
Source RPM : readline-6.2-9.el7.src.rpm
Build Date : 2014年06月10日 星期二 02時52分20秒
Build Host : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html
Summary : A library for editing typed command lines
Description :
The Readline library provides a set of functions that allow users to
edit command lines. Both Emacs and vi editing modes are available. The
Readline library includes additional functions for maintaining a list
of previously-entered command lines for recalling or editing those
lines, and for performing csh-like history expansion on previous
commands.
網上只有6.2.10版本,把readline-6.2-10.el7.x86_64.rpm 下載下來進行更新操作
[root@localhost software_download]# rpm -Uvh readline-6.2-10.el7.x86_64.rpm
[root@localhost software_download]# rpm -ivh readline-devel-6.2-10.el7.x86_64.rpm
准備中... ################################# [100%]
正在升級/安裝...
1:readline-devel-6.2-10.el7 ################################# [100%]
------------------------------------------------readline devel 安裝結束--------------------------------------------------------------------------------------
------------------------------------------------tk devel 安裝開始--------------------------------------------------------------------------------------
[root@localhost software_download]# rpm -qi tk
未安裝軟件包 tk
下載tk-8.5.13-6.el7.x86_64.rpm
[root@localhost software_download]# rpm -ivh tk-8.5.13-6.el7.x86_64.rpm
錯誤:依賴檢測失敗:
libtcl8.5.so()(64bit) 被 tk-1:8.5.13-6.el7.x86_64 需要
tcl = 1:8.5.13 被 tk-1:8.5.13-6.el7.x86_64 需要
tcl >= 1:8.5.13-5 被 tk-1:8.5.13-6.el7.x86_64 需要
下載tcl-8.5.13-8.el7.x86_64.rpm
[root@localhost software_download]# rpm -ivh tcl-8.5.13-8.el7.x86_64.rpm
准備中... ################################# [100%]
正在升級/安裝...
1:tcl-1:8.5.13-8.el7 ################################# [100%]
[root@localhost software_download]# rpm -ivh tk-8.5.13-6.el7.x86_64.rpm
准備中... ################################# [100%]
正在升級/安裝...
1:tk-1:8.5.13-6.el7 ################################# [100%]
tk-devel依賴包太多,暫不安裝或者用Yum安裝吧
依賴關系解決
====================================================================================================================================================
Package 架構 版本 源 大小
====================================================================================================================================================
正在安裝:
tk-devel x86_64 1:8.5.13-6.el7 base 488 k
為依賴而安裝:
expat-devel x86_64 2.1.0-10.el7_3 base 57 k
fontconfig-devel x86_64 2.10.95-11.el7 base 128 k
freetype-devel x86_64 2.4.11-15.el7 base 356 k
libX11-devel x86_64 1.6.5-1.el7 base 980 k
libXau-devel x86_64 1.0.8-2.1.el7 base 14 k
libXft-devel x86_64 2.3.2-2.el7 base 19 k
libXrender-devel x86_64 0.9.10-1.el7 base 17 k
libxcb-devel x86_64 1.12-1.el7 base 1.0 M
tcl-devel x86_64 1:8.5.13-8.el7 base 165 k
xorg-x11-proto-devel noarch 7.7-20.el7 base 284 k
為依賴而更新:
expat x86_64 2.1.0-10.el7_3 base 81 k
fontconfig x86_64 2.10.95-11.el7 base 229 k
freetype x86_64 2.4.11-15.el7 base 392 k
libX11 x86_64 1.6.5-1.el7 base 606 k
libX11-common noarch 1.6.5-1.el7 base 164 k
libXrender x86_64 0.9.10-1.el7 base 26 k
libxcb x86_64 1.12-1.el7 base 211 k
------------------------------------------------tk devel 安裝結束--------------------------------------------------------------------------------------
開始正式安裝python3.6
釋放文件:
tar -xzvf Python-3.6.4.tgz -C /tmp
進入目錄:
cd /tmp/Python-3.6.4
配置安裝目錄,其他選項一般默認即可:
./configure --prefix=/usr/local/python3 --設立自己的python3目錄,所有的python3 的bin lib等文件都放在/usr/local/python3目錄下
接下來編譯源碼:
make
執行安裝:
make install
做一個python3的軟鏈接
[root@localhost bin]# ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3
[root@localhost bin]# python3
Python 3.6.4 (default, Jul 5 2018, 12:35:43)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit
Use exit() or Ctrl-D (i.e. EOF) to exit
>>> exit()
做一個pip3的軟鏈接
[root@localhost bin]# ln -s /usr/local/python3/bin/pip3.6 /usr/bin/pip3
[root@localhost bin]# pip3
Usage:
pip <command> [options]
Commands:
install Install packages.
download Download packages.
uninstall Uninstall packages.
freeze Output installed packages in requirements format.
list List installed packages.
show Show information about installed packages.
check Verify installed packages have compatible dependencies.
search Search PyPI for packages.
wheel Build wheels from your requirements.
hash Compute hashes of package archives.
completion A helper command used for command completion.
help Show help for commands.
至此python3已經安裝完成了
以下這段看到的網上把原來的python2軟鏈接連接到python3上了,在生產環境千萬不要這么做,測試環境可以隨便玩
cd /usr/bin
[root@qinhan bin]# ll *python*
lrwxrwxrwx. 1 root root 7 Dec 15 2016 python -> python2
lrwxrwxrwx. 1 root root 9 Dec 15 2016 python2 -> python2.7
-rwxr-xr-x. 1 root root 7136 Nov 20 2015 python2.7
#更改/usr/bin/python鏈接
[root@qinhan bin]# ln -s /usr/local/bin/python3.6 /usr/bin/python
[root@qinhan bin]# ln -s /usr/local/bin/python3.6 /usr/bin/python3
[root@qinhan bin]# ll *python*
lrwxrwxrwx 1 root root 24 Jan 11 10:10 python -> /usr/local/bin/python3.6
lrwxrwxrwx. 1 root root 9 Dec 15 2016 python2 -> python2.7
-rwxr-xr-x. 1 root root 7136 Nov 20 2015 python2.7
lrwxrwxrwx 1 root root 24 Jan 11 10:10 python3 -> /usr/local/bin/python3.6
lrwxrwxrwx. 1 root root 7 Dec 15 2016 python.backup -> python2
#查看最新python版本
[root@qinhan bin]# python -V
Python 3.6.4
#更改yum腳本的python依賴
[root@qinhan bin]# cd /usr/bin
[root@qinhan bin]# view yum
修改#!/usr/bin/python為#!/usr/bin/python2
#修改urlgrabber配置文件
[root@qinhan bin]# view /usr/libexec/urlgrabber-ext-down
修改##! /usr/bin/python 為#! /usr/bin/python2
#查看pip是否可以正常使用
[root@qinhan bin]# pip
-bash: pip: command not found
[root@qinhan bin]# pip3
Usage:
pip <command> [options]
.......
#如果還是報command not found,可以做個軟連接如下所示,這個是另外的服務器27.100上的
[root@qinhan /]# cd usr/bin
[root@qinhan bin]# pwd
/usr/bin
[root@qinhan bin]# ll pip*
lrwxrwxrwx 1 root root 27 Jan 10 16:45 pip3 -> /usr/local/python3/bin/pip3
[root@qinhan bin]#