济沧浪 济沧浪
首页
  • Git
  • Linux
  • C++
  • 设计模式
  • CUDA
  • AI
金融

LonelyTaoist

道可道非常道 名可名非常名
首页
  • Git
  • Linux
  • C++
  • 设计模式
  • CUDA
  • AI
金融
  • Git

  • Linux

  • C++

  • 设计模式

  • CUDA

  • Python

    • Centos6.7 安装 python3
      • 前言
      • 安装 openssl
      • 安装 python
      • 其他方式
  • VScode

  • AI

  • 计算机 小知识点
  • 计算机相关博客目录
  • 计算机
  • Python
2024/01/25
目录

Centos6.7 安装 python3

# Centos6.7 安装 python3

# 前言

有时候的特殊需求需要在较老版本的操作系统上使用 python3, 而此时我们会发现一些较老的操作系统发行版没有 python3,且很可能不支持安装。

python3 依赖 openssl 1.0.2 版本甚至以上(具体依赖版本和 python3 的版本有关, 如下表), 所以可知 centos6.7 自带的 openssl 1.0.1 不支持安装 python3 。(哪怕强行安装成功也会在使用到依赖了 openssl 的库时报错, 且基本网络操作都会使用到此类相关库)

python 版本 建议的 openssl 版本
Python 2.7 OpenSSL 1.0.1 及以上
Python 3.3 - 3.6 OpenSSL 1.0.2 及以上
Python 3.7 OpenSSL 1.1.0 及以上
Python 3.8 OpenSSL 1.1.1 及以上

# 安装 openssl

下载 openssl 对应版本的源码(下载地址 (opens new window))

执行如下命令

./config --prefix=($openssl安装路径) && make && make instal

# 安装 python

下载 python 对应版本的源码(下载地址 (opens new window))

首先将 $python路径/Modules/Setup.dist 原本注释的代码取消注释并填写地址

# Socket module helper for socket(2)
_socket socketmodule.c

# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
SSL=($openssl安装路径)
_ssl _ssl.c \
        -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
        -L$(SSL)/lib -lssl -lcrypto

然后添加编译 python 时的环境变量

export LDFLAGS="-L($openssl安装路径)/lib"
export CPPFLAGS="-I($openssl安装路径)/include"
export PKG_CONFIG_PATH="($openssl安装路径)/lib/pkgconfig"

最后编译 python

./configure --prefix=($python安装路径) --with-openssl=($openssl安装路径)
make && make install

# 其他方式

官方文档 (opens new window)中也提到了自定义 openssl 的安装方式。未实际测试, 不知是否符合需求。(读者测试时注意尽量不要替换操作系统自带的 openssl 以免出现意外情况)

Python >> Documentation >> Python Setup and Usage >> 2. Using Python on Unix platforms >> 2.5. Custom OpenSSL

CUDA 入门
VScode-ssh 不兼容旧版本 Linux

← CUDA 入门 VScode-ssh 不兼容旧版本 Linux→

最近更新
01
深度学习简单介绍
04/18
02
VScode-ssh 不兼容旧版本 Linux
02/08
03
CUDA 入门
12/17
更多文章>
Theme by Vdoing | Copyright © 2023-2024 苏ICP备2023014117号-1 苏公网安备 32011502011853号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式