Fixing Python NLTK SSL error when downloading NLTK data

Python NLTK SSL error when downloading NLTK data is an error which occurs when python cannot find the Certificates.command most likely because it has not been installed.

Today I try to explain why this error takes place and how to solve it, I will also add other solutions that could solve the error if possible.

Exploring the Error : Python NLTK SSL error when downloading NLTK data

This is an error which occurs when python cannot find the Certificates.command most likely because it has not been installed.

You should avoid mixing between different errors. The error message should look like the error message bellow.

NLTK SSL error when downloading NLTK data-problem-banner

Bellow is a number of tested solutions that I have tried and have worked for me.

Solution 1 : Install Certificates.command file

We have established the fact that the error occurs because the ssl certificate is missing. The fix is simple, you need to install the ssl certificate.

This can be done manually or by using the command prompt.

The first option is to use the cmd. Please open the cmd as admin to avoid any problems.

                                                                       #
#  open cmd as admin to avoid problems
/Applications/Python 3.9/Install Certificates.command
                                                                       #

You can also do this manually by navigating to this directory, please replace the x with your version of python.

Then look for the file called Install Certificates.command, Double click it to install the certificate.

                                                                       #
# look for the file called Install Certificates.command
Applications/Pythonx.x
                                                                       #

Do not forget to replace python 3.9 with your version of python.

Please try the method bellow if this one did not work.

Solution 2 : avoid the SSL check by using ssl=False

The main solution for this problem is the method above, the solution we are going to talk about is not recommended as it is more of a workaround.

You can Ignore the SSL verification completely. As a result you are going to be exposed to multiple problems like man in the middle attacks. You can add this to your code, depending on the nature of your code. Usually this goes before the operation you want to do.

                                                                       #
# this goes before the operation you want to do
...ssl=False)
                                                                       #

I hope this was enough to solve your problem. Thank you for reading.

Summing-up : 

This is the end of this article, I hope this helped you solve the error Python NLTK SSL error when downloading NLTK data or at least guided you in the right way. You can donate to our Kofi account if you feel generous but you do not Have to.

Thank you for reading, keep coding and cheers. If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/