Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSL error downloading NLTK data

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

like image 269
DyingIsFun Avatar asked Dec 27 '16 16:12

DyingIsFun


People also ask

How do I download NLTK data from python?

Run the command python -m nltk. downloader all . To ensure central installation, run the command sudo python -m nltk. downloader -d /usr/local/share/nltk_data all .

What is NLTK Download (' WordNet ')?

WordNet is a lexical database for the English language, which was created by Princeton, and is part of the NLTK corpus. You can use WordNet alongside the NLTK module to find the meanings of words, synonyms, antonyms, and more.


3 Answers

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()
like image 31
Simon O'Doherty Avatar answered Oct 19 '22 07:10

Simon O'Doherty


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.

like image 154
doctorBroctor Avatar answered Oct 19 '22 06:10

doctorBroctor


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

like image 38
Ashish Tomar Avatar answered Oct 19 '22 07:10

Ashish Tomar