Solving Python issue Macos SSL module in Python is not available (on OSX)

Python issue Macos SSL module in Python is not available (on OSX) is an error which occurs a lot to people who are using brew, virtualenv or pyenv.

My goal today is to provide a clear and detailed explanation of why this error is happening and how to solve it, we will also check out other ways to get rid of this problem for good.

Exploring the Python issue Macos SSL module in Python is not available (on OSX)

This is an error which occurs a lot to people who are using brew, virtualenv or pyenv.

Do not mix between issues. Make sure you have the same issue by double checking.

In the flowing sections I will present multiple methods that have solved the problem for me.

Solution 1 : use pyenv install 3.9.10 only after performing a nice cleanup

The first method is a step by step method. Please follow each step without missing any steps.

First, we should start by using brew in order to uninstall python

                                                                       #
brew uninstall python
                                                                       #

Then, run the second command bellow

                                                                       #
rm -rf $(pyenv root)
                                                                       #

If you have already installed pyenv-virtualenv , then we should make sure to uninstall it before uninstalling pyenv

                                                                       #
brew uninstall pyenv-virtualenv
                                                                       #

Use this brew command to remove pyenv

                                                                       #
brew uninstall pyenv
                                                                       #

Finally, now that we have removed pyenv from our system.

We can proceed to install pyenv using brew

                                                                       #
brew install pyenv
                                                                       #

Finally, install your Python version of choice ( in my case I want python 3.9.10)

                                                                       #
pyenv install 3.9.10
                                                                       #

That is it for the first method, Please try the second method if things did not workout.

Solution 2 : A different way to use pyenv to install python and also correctly install requirements.txt

The second method is also a step by step method.

The first step which you should not miss is to use brew to reinstall python

                                                                       #
brew reinstall python
                                                                       #

If that did not work, please consider removing both pyenv-virtualenv and pyenv from your system.

                                                                       #
brew uninstall pyenv pyenv-virtualenv
                                                                       #

After that make sure to use the command bellow to install both pyenv-virtualenv and pyenv

                                                                       #
brew install pyenv pyenv-virtualenv
                                                                       #

Now it is time to remove python, in this example I am going to remove python version 3.8.1

                                                                       #
pyenv uninstall 3.8.1
                                                                       #

Then, I am going to install python version 3.9.1

                                                                       #
pyenv install 3.9.1
                                                                       #

Finally, we install requirements.txt

                                                                       #
pip install -r requirements.txt
                                                                       #

I hope the fix above fixed your problem. Thank you for reading this whole article.

Summing-up : 

This is the end of our article, I hope the solutions I presented worked for you, Learning Python is a fun journey, do not let the errors discourage you. Keep coding and cheers.

Thank you for reading my blog post to the end, If you want to learn more about the Python programming language, check out the official Python Documentation : https://docs.python.org/3/