简体   繁体   English

下载NLTK数据时出现SSL错误

[英]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: 我试图在Mac OS X 10.7.5上下载NLTK 3.0以用于Python 3.6,但是我收到了SSL错误:

import nltk
nltk.download()

在此输入图像描述

I downloaded NLTK with a pip3 command: sudo pip3 install -U nltk . 我用pip3命令下​​载了NLTK: 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): 更改NLTK下载程序中的索引允许下载程序显示所有NLTK文件,但是当尝试下载所有文件时,会发生另一个SSL错误(请参阅照片底部):

在此输入图像描述

I am relatively new to computer science and am not at all savvy with respect to SSL. 我对计算机科学比较陌生,对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 无法下载nltk数据

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 NLTK下载SSL:证书验证失败

downloading error using nltk.download() 使用nltk.download()下载错误

You don't need to disable SSL checking if you run the following terminal command: 如果运行以下终端命令,则无需禁用SSL检查:

/Applications/Python 3.6/Install Certificates.command

In the place of 3.6 , put your version of Python if it's an earlier one. 3.6的位置,放置你的Python版本,如果它是较早的版本。 Then you should be able to open your Python interpreter (using the command python3 ) and successfully run nltk.download() there. 然后你应该能够打开你的Python解释器(使用命令python3 )并在那里成功运行nltk.download()

This is an issue wherein urllib uses an embedded version of OpenSSL that not in the system certificate store. 这是一个问题,其中urllib使用不在系统证书存储区中的嵌入式OpenSSL版本。 Here's an answer with more information on what's going on. 这是一个答案,提供有关正在发生的事情的更多信息。

Please see answer by @doctorBroctor. 请参阅@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 https://stackoverflow.com/a/42890688/1167890


This will work by disabling SSL checking. 这将通过禁用SSL检查来工作。

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

In Finder, search for Python 3.6 . 在Finder中,搜索Python 3.6 It will appear under Application folder. 它将出现在Application文件夹下。 Expand the Python 3.6 folder. 展开Python 3.6文件夹。 Then install certificates using "Install Certificates.command" . 然后使用“Install Certificates.command”安装证书

在此输入图像描述

要以codestar方式安装,只需手动下载模块并将其保存到nltk_data文件夹中,使用valie ./nltk_data创建一个lambda变量环境NLTK_DATA。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM