首先去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..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.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]# 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]#

centos 7 安装 python3.6 python3 安装步骤以及pip pip3安装挂载的更多相关文章

  1. 在windows系统上使用pip命令安装python的第三方库

    在windows系统上使用pip命令安装python的第三方库 通过cmd启动命令行后,直接输入pip命令,有时候命令行会提示我们pip不是一个指令,这个时候我们可以通过python的集成开发环境里面 ...

  2. 001.Pip简介安装使用

    一 PIP简介 pip类似RedHat里面的yum,使用PIP安装软件非常便捷快速. 二 PIP下载安装 方式一: [root@localhost ~]# yum install -y epel-re ...

  3. suse11 安装 python3.6 python3 安装步骤

    首先需要去网上下载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 li ...

  4. win10 anaconda3 python3.6安装tensorflow keras tensorflow_federated详细步骤及在jupyter notebook运行指定的conda虚拟环境

    本文链接:https://blog.csdn.net/weixin_44290661/article/details/1026789071. 安装tensorflow keras tensorflow ...

  5. Ubuntu16.04下安装python3.6.4详细步骤

    记录一下: Ubuntu16.04自带的python版本为python2.7和python3.5,现在想要安装python3.6.4,注意:系统自带的python版本别删除 步骤: # 官网下载安装包 ...

  6. centos 7系统,解决python3.x 安装后使用yum不能安装的问题(错误:urlgrabber-ext-down | KeyboardInterrupt)

    1.在安装python3.xx版本后,通过yum去安装软件会出现问题,目前我遇到的有2种问题 比如显示:urlgrabber-ext-down Downloading packages: File & ...

  7. CentOS 7 下如何进行Python3的独立安装

    一.部署准备工作 部署环境工具检查及安装 1)安装epel-release库,以防db4-devel依赖安装失败 1 yum -y install epel-release 2)安装外部函数库(lib ...

  8. python3 与 pip3 安装与使用

    1. yum -y install openssl* (pip依赖ssl环境) 2.编译安装python3 下载地址:https://www.python.org/ftp/python/ .tgz c ...

  9. Windows下安装python2和python3双版本

    现在大家常用的桌面操作系统有:Windows.Mac OS.ubuntu,其中Mac OS 和 ubuntu上都会自带python.这里我们只介绍下Windows(我用的Win10)环境下的pytho ...

随机推荐

  1. visual studio build and rebuild 的区别

    build 只编译发生改变的dll, (如下, 我只修改了web API,build的时候, 只有webAPI.dll发生更新) rebuild = clean + build (如下, 本项目中dl ...

  2. SCP对拷如何连接指定端口远程主机

    SCP对拷如何连接指定端口(非22端口)的远程主机 scp  -P  远程端口号  本机待拷贝文件路径 远程主机用户名@远程主机地址:远程主机目的路径 注意:  1.  参数-P 的位置一定要紧跟在s ...

  3. nginx安装扩展 sub_filter&http_ssl_module

    nginx之所以轻,因为默认没有安装各种各样的扩展: nginx安装扩展插件: 下面列出两个可能会用到的插件 一.sub_filter内容过滤器,这个在nginx做http转发的时候会很常用 1.下载 ...

  4. 将文件转换成byte[]数组

    代码 /// <summary> /// 将文件转换成byte[] 数组 /// </summary> /// <param name="fileUrl&quo ...

  5. python 数据类型 之 利用 dict 模仿 switch语句功能

    Python本身并不提供Switch的语法功能,为了能够解决类似switch分支需求的问题,我们可以使用字典代替实现. 解决思路: 利用字典取值的get方法的容错性,处理switch语句中的defau ...

  6. Oracle_PL/SQL(1) 匿名块

    1. PL/SQL 简介PL/SQL是一种比较复杂的程序设计语言, 用于从各种环境中访问Oracle数据库.为什么使用PL/SQL?Orade是一种关系型数据库, 用来访问关系型数据库的语言是 “结构 ...

  7. linux 管道符与通配符

    ###管道符 *命令格: 命令1 | 命令2 //命令1的正确输出作为命令2的操作对象 ll | more netstat -an | grep xxx 通配符 类似于正则表达式 ? 一个以上 [] ...

  8. PAT 1036 跟奥巴马一起编程(15)(代码)

    1036 跟奥巴马一起编程(15)(15 分) 美国总统奥巴马不仅呼吁所有人都学习编程,甚至以身作则编写代码,成为美国历史上首位编写计算机代码的总统.2014年底,为庆祝"计算机科学教育周& ...

  9. Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986

    最近在Tomcat上配置一个项目,在点击一个按钮,下载一个文件的时候,老是会报上面的错误.试了很多方法,如对server.xml文件中,增加MaxHttpHeaderSize的大小,改端口,改Tomc ...

  10. NC 6系预警类型注册

    在实际开发预警任务中,因为模块是新创建的,所以开发预警,就要在相应的节点模块注册.但这样代码就得放在相应的模块中,注册个预警类型,就可以把代码直接放在自己新建的模块. .先执行新建模块语句 inser ...