88

I get the following error when trying to install Punkt for nltk:

nltk.download('punkt')    
 [nltk_data] Error loading Punkt: <urlopen error [SSL:
 [nltk_data]     CERTIFICATE_VERIFY_FAILED] certificate verify failed
 [nltk_data]     (_ssl.c:590)>
False
agiledatabase
  • 29
  • 1
  • 4
user3429986
  • 1,035
  • 1
  • 7
  • 8

17 Answers17

179

TLDR: Here is a better solution: https://github.com/gunthercox/ChatterBot/issues/930#issuecomment-322111087

Note that when you run nltk.download(), a window will pop up and let you select which packages to download (Download is not automatically started right away).

To complement the accepted answer, the following is a complete list of directories that will be searched on Mac (not limited to the one mentioned in the accepted answer): - '/Users/YOUR_USERNAME/nltk_data' - '/usr/share/nltk_data' - '/usr/local/share/nltk_data' - '/usr/lib/nltk_data' - '/usr/local/lib/nltk_data' - '/Users/YOUR_USERNAME/YOUR_VIRTUAL_ENV_DIRECTORY/nltk_data' - '/Users/YOUR_USERNAME/YOUR_VIRTUAL_ENV_DIRECTORY/share/nltk_data' - '/Users/YOUR_USERNAME/YOUR_VIRTUAL_ENV_DIRECTORY/lib/nltk_data'

In case the link above dies, here is the solution pasted in its entirety:

import nltk
import ssl

try:
    _create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
    pass
else:
    ssl._create_default_https_context = _create_unverified_https_context

nltk.download()

Run the above code in your favourite Python IDE or via the command line.

pookie
  • 3,796
  • 6
  • 49
  • 105
fstang
  • 5,607
  • 4
  • 25
  • 26
  • 5
    Worked like a gem – Jason Kao Jun 23 '19 at 01:38
  • Yes, the download when to my Users directory path and it worked like a charm. Very helpful since I did not have admin privileges. I actually had tried the accepted answer with the help of an admin standing over my shoulder, and that did not work for me. – demongolem Dec 04 '19 at 18:39
  • years later, this solution still works! Thank you! – User2345 Jan 29 '22 at 20:48
  • The solution didn't work for me and it may not be enough for a separate answer on here, BUT, for the record and what has worked for me is to disable my VPN. In other words, a connection may sometimes not be established with this error message in return, if the case of your VPN is blacklistted etc. – Majte Jan 11 '23 at 21:29
  • For some reason I wasn't able to click on- and download the module I needed from the launched window. It just didn't install. To fix that I used the exact same code as above but added the identifier inside nltk.downlaod(). The model I needed had the identifier "punkt", hence replacing nltk.download() with nltk.download('punkt') by-passed the window and downloaded my package. Other than that, a perfect solution, thanks, i'm upvoting. – chilifan Jun 27 '23 at 19:05
64

This works by disabling SSL check!

import nltk
import ssl

try:
    _create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
    pass
else:
    ssl._create_default_https_context = _create_unverified_https_context

nltk.download()
ishwardgret
  • 1,068
  • 8
  • 10
39

Run the Python interpreter and type the commands:

import nltk
nltk.download()

from here: http://www.nltk.org/data.html

if you get an SSL/Certificate error, run the following command

bash /Applications/Python 3.6/Install Certificates.command

from here: ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)

Selvaram G
  • 727
  • 5
  • 18
Adi
  • 548
  • 5
  • 5
29

Search 'Install Certificates.command' in the finder and open it.

Then do the following steps in the terminal:

python3
import nltk
nltk.download()
xxx
  • 1,153
  • 1
  • 11
  • 23
yash
  • 311
  • 3
  • 2
28

The downloader script is broken. As a temporal workaround can manually download the punkt tokenizer from here and then place the unzipped folder in the corresponding location. The default folders for each OS are:

  • Windows: C:\nltk_data\tokenizers
  • OSX: /usr/local/share/nltk_data/tokenizers
  • Unix: /usr/share/nltk_data/tokenizers
elyase
  • 39,479
  • 12
  • 112
  • 119
11

This is how I solved it for MAC OS. Initially after installing nltk, I was getting the SSL error.

Solution: Goto

cd /Applications/Python\ 3.8

Run the command

./Install\ Certificates.command

Now if you try again, it should work!

Thanks a lot to this article!

Sreekiran A R
  • 3,123
  • 2
  • 20
  • 41
7

You just need to Install the certificate doing this simple step

In the python application folder double-click on the file 'Certificates.command'

this will make a prompt window show in your screen and basically will automatically install the certificate for you, close this window and try again.

thiago89
  • 103
  • 1
  • 5
4

My solution is:

  • Download punkt.zip from here and unzip
  • Create nltk_data/tokenizers folders under home folder
  • Put punkt folder under tokenizers folder
gocen
  • 103
  • 1
  • 10
3

There is a very simple way to fix all of this as written in the formal bug report for anyone else coming across this problem recently (e.g. 2019) and using MacOS. From the bug report at https://bugs.python.org/issue28150:

...there is a simple double-clickable or command-line-runnable script ("/Applications/Python 3.6/Install Certificates.command") that does two things: 1. uses pip to install certifi and 2. creates a symlink in the OpenSSL directory to certifi's installed bundle location.

Simply running the "Install Certificates.command" script worked for me on MacOS (10.15 beta as of this writing) and I was off and running.

Michael Hawkins
  • 2,793
  • 1
  • 19
  • 33
  • 1
    Using just released MacOS 10.15 and was unable to find "Install Certificates.command" file. There is no `/Applications/Python 3.x` directory. – Kirill Oct 09 '19 at 16:27
  • Which version of Python are you using? – Michael Hawkins Oct 18 '19 at 21:12
  • Python 3.7.3 from `/usr/bin/python3` pre-installed on macOS 10.15 – Kirill Oct 18 '19 at 22:04
  • I'm also using Python 3, but not pre-installed. Perhaps that is the difference. Try installing another version maybe and seeing if the directory exists for you to take these actions. Either that or the directory was changed in later versions (after 3.6), though I doubt it. I'll verify when I get back to my Mac. – Michael Hawkins Oct 22 '19 at 00:03
3

For mac users, just copy paste the following in the terminal:

/Applications/Python\ 3.10/Install\ Certificates.command ; exit;
xxx
  • 1,153
  • 1
  • 11
  • 23
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – user11717481 Oct 18 '22 at 10:21
2

My solution after nothing worked. I navigated, via the GUI to the Python 3.7 folder, opened the 'Certificates.command' file in terminal and the SSL issue was immediately resolved.

2

A bit late to the party but I just entered Certificates.command into Spotlight which found it and ran it. All fixed in seconds.

I'm running mac Catalina and using python 3.7 installed by Homebrew

Chez
  • 961
  • 1
  • 9
  • 20
1

It means that you are not using HTTPS to work consistently with other run time dependencies for Python etc.

If you are using Linux (Ubuntu)

~$ sudo apt-get install ca-certificates

Should solve the issue.

If you are using this in a script with a docker file, you have to make sure you have install the the ca-certificates modules in your docker file.

Sibeesh Venu
  • 18,755
  • 12
  • 103
  • 140
enkidoo
  • 75
  • 6
0

First go to the path /Applications/Python 3.6/ and run Install Certificates.command

You will admin rights for the same.

If you are unable to download it, then as other answer suggest you can download directly and place it. You need to place them in the following directory structure.

> nltk_data
          > corpora
                   > brown
                   > conll2000
                   > movie_reviews
                   > wordnet
          > taggers
                   > averaged_perceptron_tagger
          > tokenizers
                      > punkt
Rahul R
  • 111
  • 6
0

Updating the python certificates worked for me.

At the top of your script, keep:

import nltk
nltk.download('punkt')

In a separate terminal run (Mac):

bash /Applications/Python <version>/Install Certificates.command
0

For mac: Search Install Certificates.command in the finder and open it.

After successfully finished, just start download

import nltk
nltk.download('wordnet')
SaimumIslam27
  • 971
  • 1
  • 8
  • 14
-1

For me, the solution was much simpler: I was still connected to my corporate network/VPN which blocks certain types of downloads. Switching the network made the SSL error disappear.

felixjrd
  • 65
  • 2
  • 10