00 实验环境
# 发行版信息[root@localhost ~]# cat /etc/redhat-releaseCentOS Linux release 7.6.1810 (Core)# 内核[root@localhost ~]# uname -r3.10.0-957.el7.x86_64# 时间chery@cherysc ~ date2019年 1月 9日 星期三 10时47分07秒 CST
01 实验目的
在本机上通过编译安装的方式安装并配置python3
02 实验软件选择
020 python3选择版本
源码编译方式:https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz
小助手🐖 如果发现官方源太慢可以使用 淘宝源
https://npm.taobao.org/mirrors/python/
03 准备安装
030 准备安装软件()
# 使用官方源[root@chery tools]# wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz# 也可以使用淘宝源[root@chery tools]# wget https://npm.taobao.org/mirrors/python/3.6.8/Python-3.6.8.tgz
031 准备依赖包
yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel -y
如果不安装zlib,就报错:
zipimport.ZipImportError: can’t decompress data; zlib not available
make: * [install] Error 1
04 开始安装
040 解压安装包
[root@chery tools]# tar -xvf Python-3.6.8.tgz[root@chery tools]# lsmysql-5.6.41 mysql-5.6.41.tar.gz Python-3.6.8 Python-3.6.8.tgz[root@chery tools]# cd Python-3.6.8[root@chery Python-3.6.8]# lsaclocal.m4 configure Grammar Lib Makefile.pre.in Objects PCbuild Python Toolsconfig.guess configure.ac Include LICENSE Misc Parser Programs README.rstconfig.sub Doc install-sh Mac Modules PC pyconfig.h.in setup.py
041 编辑配置
[root@chery Python-3.6.8]# ./configure --prefix=/opt/python3checking build system type... x86_64-pc-linux-gnuchecking host system type... x86_64-pc-linux-gnu.......
—prefix=/opt/python3
If you want a release build with all stable optimizations active (PGO, etc),
please run ./configure —enable-optimizations
如果您希望发布版本并且所有稳定优化都处于活动状态(PGO等),
042 开始编译
[root@chery Python-3.6.8]# make## 如果没有问题就执行下面的[root@chery Python-3.6.8]# make install
05 配置python3
050添加全局变量(推荐)
当然也可以用软连接(但是需要连接python3 和pip3),不推荐
[root@chery Python-3.6.8]# lsaclocal.m4 config.sub Include Mac Modules Programs Python setup.pybuild configure install-sh Makefile Objects pybuilddir.txt python-config Toolsconfig.guess configure.ac Lib Makefile.pre Parser pyconfig.h python-config.pyconfig.log Doc libpython3.6m.a Makefile.pre.in PC pyconfig.h.in python-gdb.pyconfig.status Grammar LICENSE Misc PCbuild python README.rst[root@chery Python-3.6.8]# cd /opt/python3/[root@chery python3]# lsbin include lib share[root@chery python3]# cd bin/[root@chery bin]# ls2to3 easy_install-3.6 idle3.6 pip3.6 pydoc3.6 python3.6 python3.6m python3-config pyvenv-3.62to3-3.6 idle3 pip3 pydoc3 python3 python3.6-config python3.6m-config pyvenv
[root@chery bin]# echo 'export PATH=/opt/python3/bin:$PATH' >> /etc/profile[root@chery bin]# tail -1 /etc/profileexport PATH=/opt/python3/bin:$PATH[root@chery bin]# source /etc/profile[root@chery bin]# echo $PATH/opt/python3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@chery bin]# python3Python 3.6.8 (default, Jan 9 2019, 10:20:25)[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linuxType "help", "copyright", "credits" or "license" for more information.>>>>>> exit();[root@chery bin]# ls2to3 easy_install-3.6 idle3.6 pip3.6 pydoc3.6 python3.6 python3.6m python3-config pyvenv-3.62to3-3.6 idle3 pip3 pydoc3 python3 python3.6-config python3.6m-config pyvenv[root@chery bin]# pip3 -Vpip 18.1 from /opt/python3/lib/python3.6/site-packages/pip (python 3.6)
懒人复制区(中途出现问题自己检查!)
首先要安装依赖
yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-develncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel -y
开启复制模式
mkdir -p /root/toolscd /root/toolswget https://npm.taobao.org/mirrors/python/3.6.8/Python-3.6.8.tgztar -xf Python-3.6.8.tgzcd Python-3.6.8./configure --prefix=/opt/python3make && make installcd /opt/python3/bin/echo 'export PATH=/opt/python3/bin:$PATH' >> /etc/profiletail -1 /etc/profilesource /etc/profileecho $PATHpython3
国内pip源
https://mirrors.tuna.tsinghua.edu.cn/help/pypi/
临时使用
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
注意,simple 不能少, 是 https 而不是 http
设为默认
升级 pip 到最新的版本 (>=10.0.0) 后进行配置:
pip install pip -Upip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
