So, you have an old OS like CentOS 7 or Ubuntu 16.04, and you want to install a recent Python version like Python 3.11. The problem is that the openssl library in these operating systems is old, and you need a newer version of openssl to be able to use pip.
This post will discuss how to compile and install openssl on Ubuntu 16.04 and CentOS7 to install Python 3.11
Install requirements
CentOS 7
yum install -y make gcc perl-core pcre-devel wget zlib-devel gcc openssl-devel bzip2-devel libffi-devel bzip2-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
Not: If build Python3.13+, you need to update gcc to be able to use --enable-optimizations by enabling SCL and Install GCC 9. Check this article to know how to do so.
Ubuntu 16.04
apt install -y make gcc perl-core pcre-devel wget zlib-dev gcc openssl-dev bzip2-dev libffi-dev
Download/Build openssl
- Go to openssl website and download a supported version.
- Extract the downloaded archive
tar xzf openssl-Ver.tar.gz
cd openssl-Ver
- Configure the build
./Configure linux-x86_64 --prefix=/opt/openssl --openssldir=/opt/openssl shared
- Build and Install
make install
ldconfig /opt/openssl/lib64/
- Test Build
/opt/openssl/bin/openssl version
- Add the built components to the environment
export CPPFLAGS="-I/opt/openssl/include"
export LDFLAGS="-L/opt/openssl/lib64"
export PKG_CONFIG_PATH="/opt/openssl/lib/pkgconfig"
unset PYTHONHOME
unset PYTHONPATH
Download and Compile Python
- Download the source from
https://www.python.org/downloads/source/ - Extract the source
- run
./configure --enable-optimizations --enable-shared --with-openssl=/opt/openssl | grep -i ssl
Note Make sure that openssl is from /opt/ssl as screenshot below
- Run make
make
make altinstall
and you are done.
Notes:
-
libffiis crucial, so don't forget it. -
--enable-sharedis required if you will compile any library with C Extension. - pip will be installed by default.
- If you get
/usr/local/bin/python3.7: error while loading shared libraries: libpython3.11.so.1.0: cannot open shared object file: No such file or directory, then do the following -
export LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/libor sudo ldconfig /usr/local/lib

Top comments (0)