CentOS7环境下源码安装Python3.5
因为前一段时间折腾过MySQL5.7的源码安装,所以这次Python3.5的安装问题不大,主要还是pip的问题。
CentOS7环境下Python3.5大致的安装过程
# 官网下载源码文件包
$ wget https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tar.xz
# 解压
$ tar xvJf Python-3.5.1.tar.xz
# 进入目录
$ cd Python-3.5.1
# 建立文件夹(直接在目录编译、安装也可以)
$ mkdir bld
$ cd bld/
# 生成Makefile
$ ../configure
# 编译
$ make all -j 3
# 安装
$ make install
# 查看安装后的位置 里面包含了CentOS自带的2.7版本和新安装的3.5版本(最好不要改动系统自带的版本,因为系统可能某些地方依赖之前的2.7版本)
$ whereis python
python: /usr/bin/python2.7 /usr/bin/python /usr/bin/python2.7-config /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/local/bin/python3.5m /usr/local/bin/python3.5 /usr/local/bin/python3.5m-config /usr/local/bin/python3.5-config /usr/local/lib/python3.5 /usr/include/python2.7 /usr/share/man/man1/python.1.gz
在安装完Python3.5后发现,pip并没有一同安装到
看了下官方文档介绍:
Do I need to install pip?
pip is already installed if you're using Python 2 >=2.7.9 or Python 3 >=3.4 downloaded frompython.org, but you'll need to upgrade pip.
Additionally, pip will already be installed if you're working in a Virtual Envionment created byvirtualenv or pyvenv.
这样很不科学嘛,所以就尝试着文档里面用另外一种方法去安装pip
Installing with get-pip.py
To install pip, securely download get-pip.py.
Then run the following: python get-pip.py
在安装的过程中出现了错误:
ImportError: cannot import name HTTPSHandler
去网上查找原因,大概是因为缺少了openssl和openssl-devel和krb5-devel
我的环境是CentOS7,使用yum安装了一下:
$ yum install openssl openssl-devel -y
$ yum install krb5-devel
重新编译和安装了一下Python3.5
# 最后提示内容
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-7.1.2 setuptools-18.2
# pip已经自动安装了(可能是因为之前依赖不完全,所以在第一次安装mysql的时候,自动安装pip失败了)
$ pip3 --version
pip 7.1.2 from /usr/local/lib/python3.5/site-packages (python 3.5)
# 升级一下
$ /usr/local/bin/pip3 install -U pip
相关链接
pip官方文档:
https://pip.pypa.io/en/stable/installing/#upgrading-pip
下面关于Python的文章您也可能喜欢,不妨看看:
Python 的详细介绍:请点这里
Python 的下载地址:请点这里