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()

4 Answers 4

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.

11
  • 1
    works like a charm. note: still need to run nltk.download() after this step.
    – Ascendant
    Mar 23, 2017 at 19:15
  • 5
    how to do this for ubuntu?
    – weima
    Jun 29, 2017 at 13:23
  • 2
    I don't have this filepath (mac) for some reason. I downloaded python through Anaconda, if that makes any difference. Sep 6, 2017 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 1, 2017 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, 2018 at 10:00
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()
5
  • 1
    Just a heads up, panlex_lite is pretty big, so it may appear frozen. Check your console for any errors. Dec 27, 2016 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. Dec 27, 2016 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, 2016 at 23:10
  • This solution worked for me using the homebrew (brew.sh) package manager on macOS 10.13.1
    – Gareth
    Nov 21, 2017 at 9:36
  • 2 years later, this answer is still working perfectly. Thanks!! Apr 2, 2019 at 1: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

1
  • 2
    Great this helps if you're on a MAC! Nov 4, 2018 at 16:17
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.