源码编译安装python3.12没有ssl模块,python3.12 ModuleNotFoundError: No module named ‘_ssl‘
# python
Python 3.12.12 (main, Nov 25 2025, 06:21:09) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.12/ssl.py", line 100, in <module>
import _ssl # if we can't import it, let the error propagate
^^^^^^^^^^^
ModuleNotFoundError: No module named '_ssl'
>>>
参考:https://docs.python.org/3/using/unix.html#on-linux
curl -O https://www.openssl.org/source/openssl-VERSION.tar.gz
tar xzf openssl-VERSION
pushd openssl-VERSION
./config \
--prefix=/usr/local/custom-openssl \
--libdir=lib \
--openssldir=/etc/ssl
make -j1 depend
make -j8
make install
完整执行命令:
wget "https://gh-proxy.org/https://github.com/openssl/openssl/releases/download/openssl-3.5.4/openssl-3.5.4.tar.gz"
tar -xvf openssl-3.5.4.tar.gz
cd openssl-3.5.4/
./config --prefix=/usr/local/openssl/ --libdir=lib --openssldir=/etc/ssl
make -j 4 && make install
Ubuntu apt-get install libssl-dev
重新编译Pyton安装
tar -xvf Python-3.12.12.tar.xz
cd Python-3.12.12
./configure -C \
--with-openssl=/usr/local/openssl \
--with-openssl-rpath=auto \
--prefix=/usr/local/python-3.12
#install
make -j 4 && make install
###做个软件链接
ln -s /usr/local/python3.12/bin/python3.12 /usr/bin/python3

