首先去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 zlibName : zlibVersion : 1.2.7Release : 17.el7Architecture: x86_64Install Date: 2018年03月13日 星期二 18时53分26秒Group : System Environment/LibrariesSize : 185710License : zlib and BoostSignature : RSA/SHA256, 2016年11月21日 星期一 05时05分07秒, Key ID 24c6a8a7f4a80eb5Source RPM : zlib-1.2.7-17.el7.src.rpmBuild Date : 2016年11月06日 星期日 02时09分15秒Build Host : worker1.bsys.centos.orgRelocations : (not relocatable)Packager : CentOS BuildSystem <http://bugs.centos.org>Vendor : CentOSURL : http://www.zlib.net/Summary : The compression and decompression libraryDescription :Zlib is a general-purpose, patent-free, lossless data compressionlibrary which is used by many different programs.
随后根据版本包找到对应的rpm包
[root@localhost software_download]# lszlib-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 bzip2Name : bzip2Version : 1.0.6Release : 13.el7Architecture: x86_64Install Date: 2018年03月13日 星期二 18时54分02秒Group : Applications/FileSize : 83791License : BSDSignature : RSA/SHA256, 2015年11月25日 星期三 22时18分37秒, Key ID 24c6a8a7f4a80eb5Source RPM : bzip2-1.0.6-13.el7.src.rpmBuild Date : 2015年11月20日 星期五 13时04分52秒Build Host : worker1.bsys.centos.orgRelocations : (not relocatable)Packager : CentOS BuildSystem <http://bugs.centos.org>Vendor : CentOSURL : http://www.bzip.org/Summary : A file compression utilityDescription :Bzip2 is a freely available, patent-free, high quality data compressor.Bzip2 compresses files to within 10 to 15 percent of the capabilitiesof the best techniques available. However, bzip2 has the added benefitof being approximately two times faster at compression and six timesfaster at decompression than those techniques. Bzip2 is not thefastest compression utility, but it does strike a balance between speedand 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 opensslName : opensslEpoch : 1Version : 1.0.1eRelease : 60.el7Architecture: x86_64Install Date: 2018年03月13日 星期二 18时54分55秒Group : System Environment/LibrariesSize : 1611673License : OpenSSLSignature : RSA/SHA256, 2016年11月21日 星期一 03时48分52秒, Key ID 24c6a8a7f4a80eb5Source RPM : openssl-1.0.1e-60.el7.src.rpmBuild Date : 2016年11月06日 星期日 11时49分26秒Build Host : worker1.bsys.centos.orgRelocations : (not relocatable)Packager : CentOS BuildSystem <http://bugs.centos.org>Vendor : CentOSURL : http://www.openssl.org/Summary : Utilities from the general purpose cryptography library with TLS implementationDescription :The OpenSSL toolkit provides support for secure communications betweenmachines. OpenSSL includes a certificate management tool and sharedlibraries which provide various cryptographic algorithms andprotocols.
这个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 ncursesName : ncursesVersion : 5.9Release : 14.20130511.el7_4Architecture: x86_64Install Date: 2018年07月05日 星期四 11时52分01秒Group : System Environment/BaseSize : 439378License : MITSignature : RSA/SHA256, 2017年09月07日 星期四 20时43分11秒, Key ID 24c6a8a7f4a80eb5Source RPM : ncurses-5.9-14.20130511.el7_4.src.rpmBuild Date : 2017年09月07日 星期四 06时08分29秒Build Host : c1bm.rdu2.centos.orgRelocations : (not relocatable)Packager : CentOS BuildSystem <http://bugs.centos.org>Vendor : CentOSURL : http://invisible-island.net/ncurses/ncurses.htmlSummary : Ncurses support utilitiesDescription :The curses library routines are a terminal-independent method ofupdating character screens with reasonable optimization. The ncurses(new curses) library is a freely distributable replacement for thediscontinued 4.4 BSD classic curses library.
This package contains support utilities, including a terminfo compilertic, a decompiler infocmp, clear, tput, tset, and a termcap conversiontool 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 : sqliteVersion : 3.7.17Release : 8.el7Architecture: x86_64Install Date: 2018年03月13日 星期二 18时53分31秒Group : Applications/DatabasesSize : 814231License : Public DomainSignature : RSA/SHA256, 2015年11月25日 星期三 23时40分39秒, Key ID 24c6a8a7f4a80eb5Source RPM : sqlite-3.7.17-8.el7.src.rpmBuild Date : 2015年11月20日 星期五 16时45分59秒Build Host : worker1.bsys.centos.orgRelocations : (not relocatable)Packager : CentOS BuildSystem <http://bugs.centos.org>Vendor : CentOSURL : http://www.sqlite.org/Summary : Library that implements an embeddable SQL database engineDescription :SQLite is a C library that implements an SQL database engine. A largesubset of SQL92 is supported. A complete database is stored in asingle disk file. The API is designed for convenience and ease of use.Applications that link against SQLite can enjoy the power andflexibility of an SQL database without the administrative hassles ofsupporting a separate database server. Version 2 and version 3 binariesare 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 readlineName : readlineVersion : 6.2Release : 9.el7Architecture: x86_64Install Date: 2018年03月13日 星期二 18时53分31秒Group : System Environment/LibrariesSize : 460408License : GPLv3+Signature : RSA/SHA256, 2014年07月04日 星期五 12时47分34秒, Key ID 24c6a8a7f4a80eb5Source RPM : readline-6.2-9.el7.src.rpmBuild Date : 2014年06月10日 星期二 02时52分20秒Build Host : worker1.bsys.centos.orgRelocations : (not relocatable)Packager : CentOS BuildSystem <http://bugs.centos.org>Vendor : CentOSURL : http://cnswww.cns.cwru.edu/php/chet/readline/rltop.htmlSummary : A library for editing typed command linesDescription :The Readline library provides a set of functions that allow users toedit command lines. Both Emacs and vi editing modes are available. TheReadline library includes additional functions for maintaining a listof previously-entered command lines for recalling or editing thoselines, and for performing csh-like history expansion on previouscommands.
网上只有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 installpython3.6程序的执行文件:/usr/local/python3/bin/python3.6 python3.6应用程序目录:/usr/local/python3/lib/python3.6 pip3的执行文件:/usr/local/python3/bin/pip3 pyenv3的执行文件:/usr/local/python3/bin/pyenv-3.6
做一个python3的软链接
[root@localhost bin]# ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3[root@localhost bin]# python3Python 3.6.4 (default, Jul 5 2018, 12:35:43) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linuxType "help", "copyright", "credits" or "license" for more information.>>> exitUse 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 -> python2lrwxrwxrwx. 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.6lrwxrwxrwx. 1 root root 9 Dec 15 2016 python2 -> python2.7-rwxr-xr-x. 1 root root 7136 Nov 20 2015 python2.7lrwxrwxrwx 1 root root 24 Jan 11 10:10 python3 -> /usr/local/bin/python3.6lrwxrwxrwx. 1 root root 7 Dec 15 2016 python.backup -> python2
#查看最新python版本
[root@qinhan bin]# python -VPython 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]#
转载于:https://www.cnblogs.com/qinhan/p/8267014.html
相关资源:数据结构—成绩单生成器