Python 下载 NLTK 数据时出现 SSL 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41348621/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 00:51:21  来源:igfitidea点击:

SSL error downloading NLTK data

pythonmacossslssl-certificatenltk

提问by GoldenGremlin

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:

我正在尝试下载 NLTK 3.0 以在 Mac OS X 10.7.5 上与 Python 3.6 一起使用,但出现 SSL 错误:

import nltk
nltk.download()

enter image description here

在此处输入图片说明

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

我下载NLTK与PIP3命令: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 错误(参见照片底部):

enter image description here

在此处输入图片说明

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() 下载错误

回答by doctorBroctor

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. Then you should be able to open your Python interpreter (using the command python3) and successfully run nltk.download()there.

代替3.6,如果它是较早的版本,请放置您的 Python 版本。然后你应该能够打开你的 Python 解释器(使用命令python3)并在nltk.download()那里成功运行。

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

这是一个问题,其中urllib使用不在系统证书存储中的嵌入式 OpenSSL 版本。这是有关正在发生的事情的更多信息的答案

回答by Simon O'Doherty

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

请参阅@doctorBroctor 的回答。使用起来更正确、更安全。在下面留下答案,因为它可能对其他东西有用。

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

回答by Ashish Tomar

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

在 Finder 中,搜索Python 3.6. 它将出现在应用程序文件夹下。展开Python 3.6文件夹。然后使用"Install Certificates.command" 安装证书

enter image description here

在此处输入图片说明

回答by bernardo

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.

要在 codestar 中安装唯一的方法是手动下载模块并将它们保存到 nltk_data 文件夹中,使用 valie ./nltk_data 创建一个 lambda 变量环境 NLTK_DATA。