You probably have already successfully installed Python from source on your Mac, but are running into an SSL error. Some Google searching has told you that you need to compile Python with OpenSSL support on your Mac. But how the heck do you do that in Python 3?
Python with SSL on Mac
Let’s first take a look at the two common errors that indicate that you must build Python from source with OpenSSL support on Mac.
1.) You try to install a package via pip and you get a Can’t connect to HTTPS URL because the SSL module is not available error:
$ pip install pandas pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. Collecting pandas Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/pandas/ Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/pandas/ Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/pandas/ Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/pandas/ Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/pandas/ Could not fetch URL https://pypi.org/simple/pandas/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pandas/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)) - skipping Could not find a version that satisfies the requirement pandas (from versions: ) No matching distribution found for pandas
2.) You try to import ssl in Python 3 and you see a No module named _ssl error like below:
>>> import ssl Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/User/tony/opt/py36/lib/python3.6/ssl.py", line 101, in <module> import _ssl # if we can't import it, let the error propagate ModuleNotFoundError: No module named '_ssl'
The problem is because the version of openssl that ships with Mac does not expose the headers and libraries necessary for Python to hook into. You may have been able to install Python from source on Mac without any errors, but it doesn’t have SSL support so you aren’t able to pip install anything from pypi.org or import the SSL Python package.
Compiling Python with OpenSSL Support

Unfortunately, you will have to recompile Python. Assuming that you have Homebrew installed, make sure that you have the latest Homebrew version of openssl installed.
$ brew install openssl
Find the location of the openssl prefixes in brew with the following command.
$ brew --prefix openssl /usr/local/opt/openssl
Recompile Python and explicitly tell it where to find openssl with CPPFLAGS and LDFLAGS.
./configure CPPFLAGS="-I/usr/local/opt/openssl/include" LDFLAGS="-L/usr/local/opt/openssl/lib" make make install
After the make install finishes, you will have a compiled version of Python with OpenSSL. You should have no problem importing the ssl Python package or installing Python package via pip.
Let me know if you have any questions in comments below. I’d be more than happy to do my best to help you out.
And don’t forget to check out my other Python tutorials here.
Happy coding!
Thank you so much!
Happy to help 🙂
Hi Tony,
This has been a life saver thanks so much! A couple of places I got tripped up
1) I think the code in your vid saves Python to /usr/local/bin, although you then later reference Users/tonyf..
2) I had this the issue with virtualenv described here: https://stackoverflow.com/questions/39964635/error-virtualenv-command-not-found-but-install-location-is-in-pythonpath?noredirect=1&lq=1
I fixed it by using this command python -m virtualenv ~/env/py37 -p /usr/local/bin/python3
Hope that is helpful.
Cheers,
Linz
Appreciate you for taking the time to share this. I’m sure it will be helpful to others who run into this virtualenv issue.
This was so helpful! Thanks!! And then I’m curious, How did you figure out the way to solve the problem?
You’re quite welcome. Stackoverflow is always my friend when trying to solve a problem like this 🙂
Hello Tony,
great job but I have a trouble like this:
“MacBook-di-Andy:Downloads Andy$ wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
dyld: Library not loaded: /usr/local/opt/openssl@1.1/lib/libssl.1.1.dylib
Referenced from: /usr/local/bin/wget
Reason: image not found
Abort trap: 6
MacBook-di-Andy:Downloads Andy$”
What can I do?
Many Thanks
Hi Andrea. I am not familiar with this error. After some research, it seems like a lot of people were able to resolve this issue by following this guide: https://github.com/Homebrew/legacy-homebrew/issues/26544
Hope this helps!
THanks for your post
pyenv install (python_wanted_version)
would also do all this work for fine
Thanks for the post! This helped fix my issue!
Happy to hear that 🙂
FYI: Python 3.10 has a –with-openssl= configure option, so you can use:
./configure –with-openssl=/usr/local/opt/openssl