After upgrading the Ubuntu I found some of my Python scripts start to showing this error “Can’t connect to HTTPS URL because the SSL module is not available”. This actually is a system-wide issue due to some of the dependency became missing.
The general guidance to fix this error is:
- Install the lost dependency
- Re-install Python
Table of Contents
Install the lost dependency
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
Re-install Python
The most straightforward for fixing the system Python is probably to download the Python source package for your Python version, compile, and install.
In my case I also had to fix the python versions I installed from pyenv. Of course I did not want to uninstall the current installation because I have quite a few virtualenvs that will be removed if I do uninstalled. After experimenting, it actually works just executes the installation for the versions I have again, and my virtualenvs will stay.
For example, for my Python 3.8.3 installation:
pyenv install 3.8.3
The script will ask you if you are sure since you already have the directory, just say yes and let it install again and it works.