1

I'm on Ubuntu 22.04.1 which comes whit its own python3.11, where pip works perfectly. If I install other python versions through apt-get (sudo apt-get install python3.10) the related pip works perfectly.

But I just installed an alternative python version (3.7.9 ) from source (I'm not able to use apt for this python version), doing the following

cd usr/lib
sudo wget https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tgz
sudo tar xzf Python-3.7.9.tg
cd Python-3.7.9
sudo ./configure --enable-optimizations
sudo make altinstall

Python3.7 works fine, but if I try to install any package (using pip3.7 or, after creating a virtualenv based on python3.7, using pip) I get the following warning

WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

Followed by the error

ERROR: Could not find a version that satisfies the requirement numpy (from versions: none)
ERROR: No matching distribution found for numpy 

I'm sure I have Openssl installed because other versions of python don't give probelms with pip (also I can see ssl in the folder /etc/ssl) so the problem seems to be related only on a link between ssl and python installed from source.

Any suggestions?

5
  • Hint 1: Avoid sudo when you don't really need it. You don't need sudo to download and compile, only need it for make install. Commented Nov 25, 2022 at 21:35
  • Hint 2: Watch output from ./configure. Yes, it's large and mostly boring. But there're hidden gems in the pile. Especially watch problems with absent libraries. Commented Nov 25, 2022 at 21:37
  • Hint 3: To compile Python's _ssl.so module you need OpenSSL development files (headers and link libraries). I'm not 100% sure but I think you need sudo apt install openssl-devel. After that clean, reconfigure and recompile Python. Like this: sudo chown -R $USER . && make distclean && ./configure && make && sudo make altinstall Commented Nov 25, 2022 at 21:39
  • Sorry, it's sudo apt install libssl-dev Commented Nov 25, 2022 at 21:59
  • thanks, but in my case openssl was already installed but python compiled from source is not able to 'see' it (python installed from apt-get doesn't have this problem), I think I found a solution for my specific problem, I posted it below Commented Nov 28, 2022 at 10:43

2 Answers 2

3

If it can help anyone, I found a solution: before doing

sudo ./configure --enable-optimizations
sudo make altinstall

I simply modified part of the file Modules/Setup.dist

from

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

to

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

Notice that /etc/ssl is the actual location where I have ssl installed.

After the file modification I than installed with

sudo ./configure --enable-optimizations
sudo make altinstall

And now (after eventually upgrading pip and setuptools) pip works fine.

Sign up to request clarification or add additional context in comments.

Comments

0

For Python 3.11.1 on Ubuntu 22.04.1, you do not need to modify any distribution files, just add --with-openssl-rpath=/usr/lib/x86_64-linux-gnu to the ./configure command line.

The ssl & crypto libs are in that directory, and this ensures they're located at runtime

Note this assumes you're running on an x86_64 distro, I expect there's a similar directory on ARM.

1 Comment

For aynone looking to compile python2.7.x on Ubuntu 24.04, this won't work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.