ubuntu16源码安装python3.9及ssl

本文详细介绍了如何在Ubuntu16.04上源码安装Python3.9,并特别关注了对OpenSSL 1.1.1的依赖,以确保SSL支持和pip的正常工作。首先从官网下载并编译openssl,然后配置ssl,最后编译安装Python3.9,解决import tkinter模块失败的问题。
部署运行你感兴趣的模型镜像

python新版本需要openssl 1.1.1,以支持ssl及pip下载。

1.安装openssl 1.1.1及测试

#从官网下载
# wget https://www.openssl.org/source/openssl-1.1.1n.tar.gz

#腾讯云提供的镜像
wget https://mirrors.cloud.tencent.com/openssl/source/openssl-1.1.1n.tar.gz

编译 openssl
tar -xvf openssl-1.1.1g.tar.gz
cd openssl-1.1.1g
./config shared --openssldir=/usr/local/openssl --prefix=/usr/local/openssl
make && make install

配置ssl

mv /usr/bin/openssl /usr/bin/openssl.old
mv /usr/lib/openssl /usr/lib/openssl.old
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/include/openssl /usr/include/openssl
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
ldconfig -v 


查看版本:
/wk/tools/openssl$ openssl version
OpenSSL 1.1.1n  15 Mar 2022

验证ssl编译:

#include <stdio.h>
#include <openssl/evp.h>

int main(){
        
        OpenSSL_add_all_algorithms();
        
        return 0;
}
gcc -o conftest -I/usr/local/openssl/include/ -L/usr/local/openssl/lib test_openssl.c -lssl -lcrypto -lcrypt -lpthread -ldl -lutil -lm
编译通过

2 python编译配置:

下载python版本
./configure --enable-optimizations --prefix=/opt/python3.9 --with-openssl=/usr/local/openssl --with-computed-gotos --enable-loadable-sqlite-extensions --enable-shared
make 
make install

编辑 /etc/ld.so.conf.d/python3.conf 添加一行
/opt/python3.9/lib/

ldconfig

import ssl正常:

$ /opt/python3.9/bin/python3
Python 3.9.12 (heads/master:227f566, May  1 2022, 22:05:04) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>> 

解决import tkinter模块失败问题
sudo apt install python3-tk
sudo apt install tk-dev
如仍然报错,重新编译安装下python

您可能感兴趣的与本文相关的镜像

Python3.9

Python3.9

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值