Linux 编译 python3.7

版权声明:转载请先联系并注明出处! https://blog.csdn.net/u010552731/article/details/90030234

以下是基于 CentOS 6.3 的编译记录

1. 安装依赖

yum install zlib-devel bzip2-devel openssl-devel \
ncurses-devel sqlite-devel readline-devel tk-devel \
libffi-devel libuuid-devel python-devel mysql-devel \
gcc make

2. 源码下载:

https://www.python.org/downloads/source/

解压缩:

tar -zxvf Python-3.7.3.tgz

3. cd 到 python 目录并编译

cd Python-3.7.3
./configure --prefix=/path/you/want/to/install
make
make install

编译 python3.7 大概率会遇到的问题:

1. ModuleNotFoundError: No module named '_ctypes'

解决方法:

yum -y install libffi-devel

然后重新从 configure 来一遍,记得先 make clean

2. 编译安装完 python 后使用pip3安装组件时提示:Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_PARAM_set1_host().

或在 make 的时候提示:

Failed to build these modules: _hashlib _ssl

解决方法:都是因为 openssl 的问题,根据提示可以安装 openssl1.0.2 或1.1以上版本,也可以用 LibreSSL 2.6.4 以上版本。这里推荐编译安装 LibreSSL2.7.4。

libreSSL安装

1. 下载一个大于2.6.4版本的 LibreSSL,我用的是2.7.4版本

https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/

2. 依次执行:

tar zxvf libreSSL-2.7.4.tar.gz 
cd libreSSL-2.7.4 
./configure –prefix=/usr/local/lib 
make 
make install

3. 安装完成之后:

cd /etc/ld.so.conf.d 
# 新建 
vi libressl-2.7.4.conf 
# 写入如下内容 
/usr/local/lib 
# :wq关闭文件并重新加载库文件 
ldconfig -v

4. 试一下是否安装成功:

openssl version

5. 重新configure,make,make install python3.7。记得先make clean一下。


以上

猜你喜欢

转载自blog.csdn.net/u010552731/article/details/90030234