78

I am trying to download NLTK 3.0 for use with Python 3.6 on Mac OS X 10.7.5, but am getting an SSL error:

import nltk
nltk.download()

enter image description here

I downloaded NLTK with a pip3 command: sudo pip3 install -U nltk.

Changing the index in the NLTK downloader allows the downloader to show all of NLTK's files, but when one tries to download all, one gets another SSL error (see bottom of photo):

enter image description here

I am relatively new to computer science and am not at all savvy with respect to SSL.

My question is how to simply resolve this issue?


Here is a similar question by a user who is having the same problem:

Unable to download nltk data

I decided to post a new question with screenshots, since my edit to that other question was rejected.

Similar questions which I did not find helpful:

NLTK download SSL: Certificate verify failed

downloading error using nltk.download()

Community
  • 1
  • 1
DyingIsFun
  • 1,227
  • 2
  • 10
  • 21

4 Answers4

129

You don't need to disable SSL checking if you run the following terminal command:

/Applications/Python 3.6/Install Certificates.command

In the place of 3.6, put your version of Python if it's an earlier one. Then you should be able to open your Python interpreter (using the command python3) and successfully run nltk.download() there.

This is an issue wherein urllib uses an embedded version of OpenSSL that not in the system certificate store. Here's an answer with more information on what's going on.

doctorBroctor
  • 2,018
  • 1
  • 14
  • 17
  • 1
    works like a charm. note: still need to run `nltk.download()` after this step. – Ascendant Mar 23 '17 at 19:15
  • 1
    @Dany I agree. Updated my answer. – Simon O'Doherty Jun 15 '17 at 16:11
  • 5
    how to do this for ubuntu? – weima Jun 29 '17 at 13:23
  • 2
    I don't have this filepath (mac) for some reason. I downloaded python through Anaconda, if that makes any difference. – FortuneFaded Sep 06 '17 at 21:08
  • 5
    @FortuneFaded try sh "/Applications/Python 3.6/Install Certificates.command" - The sh at the start and the quotes are important. I thought I didn't have the dir either but it turns out it was the spaces throwing me off. – K-Dawg Oct 01 '17 at 16:06
  • 9
    ... which, if you're copying and pasting into Terminal, should end up looking like this: `/Applications/Python\ 3.6/Install\ Certificates.command` – shiri Jan 21 '18 at 10:00
  • 1
    @shiri i updated the answer to be more clear about how to run the command. – dsapalo Apr 20 '18 at 07:12
  • @iwillnot I was specifically referring to the escaping due to spaces in the pathname. In other words, if copying the line from your original post ( `/Applications/Python 3.6/Install Certificates.command` ) and pasting into Terminal, Terminal will beautifully convert the path to an escaped path which now look like `/Applications/Python\ 3.6/Install\ Certificates.command`. – shiri Jun 01 '18 at 12:59
  • 1
    @shiri is this command also applicable for python on ubuntu running on Anaconda installation?? what is the path in the terminal from where this command has to be fired? I do not find any folder called /Applications/Python.. Please help – Prince Nov 25 '18 at 07:41
  • @Prince probably not directly applicable to ubuntu, as this question was specifically addressing a Mac and my comment was referencing the path in Mac. If you can find your python folder, you will likely need to run that same command: `YOUR_PATH/Install\ Certificates.command` where YOUR_PATH is replaced with the location of your python folder. – shiri Mar 07 '19 at 16:14
  • @doctorBroctor How would you do this with a virtualenv? – ds_secret Oct 17 '19 at 18:26
97

Please see answer by @doctorBroctor. It is more correct and safer to use. Leaving answer below as it might be useful for something else.

https://stackoverflow.com/a/42890688/1167890


This will work by disabling SSL checking.

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()
Simon O'Doherty
  • 9,259
  • 3
  • 26
  • 54
  • 1
    Just a heads up, panlex_lite is pretty big, so it may appear frozen. Check your console for any errors. – Simon O'Doherty Dec 27 '16 at 20:44
  • 1
    Also it's a bit buggy, so if it fails, try downloading the remaining packages individually. Or deleting a failed one from ~/ntlk_data folder(zip+ folder) and retry. – Simon O'Doherty Dec 27 '16 at 20:53
  • This worked (except for panlex_lite, which, as you point out, is buggy)! Infinite thanks. Could you explain *briefly* why I was getting the error and what your code is doing? I guess it's bypassing some kind of SSL security which was preventing me from accessing the GitHub location of the files? – DyingIsFun Dec 27 '16 at 23:10
  • This solution worked for me using the homebrew (https://brew.sh) package manager on macOS 10.13.1 – Gareth Nov 21 '17 at 09:36
  • 2 years later, this answer is still working perfectly. Thanks!! – mackycheese21 Apr 02 '19 at 01:48
27

In Finder, search for Python 3.6. It will appear under Application folder. Expand the Python 3.6 folder. Then install certificates using "Install Certificates.command".

enter image description here

Jan Černý
  • 1,268
  • 2
  • 17
  • 31
Ashish Tomar
  • 321
  • 4
  • 2
0

To install in codestar only way is manually download modules and save them into nltk_data folder, create a lambda variable environment NLTK_DATA with valie ./nltk_data.

bernardo
  • 23
  • 3