NLTK download SSL: Certificate verify failed

后端 未结 12 1958
面向向阳花
面向向阳花 2020-12-08 00:38

I get the following error when trying to install Punkt for nltk:

nltk.download(\'punkt\')    
 [nltk_data] Error loading Punkt: 

        
相关标签:
12条回答
  • 2020-12-08 00:55

    There is a very simple way to fix all of this as written in the formal bug report for anyone else coming across this problem recently (e.g. 2019) and using MacOS. From the bug report at https://bugs.python.org/issue28150:

    ...there is a simple double-clickable or command-line-runnable script ("/Applications/Python 3.6/Install Certificates.command") that does two things: 1. uses pip to install certifi and 2. creates a symlink in the OpenSSL directory to certifi's installed bundle location.

    Simply running the "Install Certificates.command" script worked for me on MacOS (10.15 beta as of this writing) and I was off and running.

    0 讨论(0)
  • 2020-12-08 00:55

    It means that you are not using HTTPS to work consistently with other run time dependencies for Python etc.

    If you are using Linux (Ubuntu)

    ~$ sudo apt-get install ca-certificates
    

    Should solve the issue.

    If you are using this in a script with a docker file, you have to make sure you have install the the ca-certificates modules in your docker file.

    0 讨论(0)
  • 2020-12-08 00:55

    A bit late to the party but I just entered Certificates.command into Spotlight which found it and ran it. All fixed in seconds.

    I'm running mac Catalina and using python 3.7 installed by Homebrew

    0 讨论(0)
  • 2020-12-08 00:58

    My solution after nothing worked. I navigated, via the GUI to the Python 3.7 folder, opened the 'Certificates.command' file in terminal and the SSL issue was immediately resolved.

    0 讨论(0)
  • 2020-12-08 01:04

    This works by disabling SSL check!

    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()
    
    0 讨论(0)
  • 2020-12-08 01:06

    TLDR: Here is a better solution: https://github.com/gunthercox/ChatterBot/issues/930#issuecomment-322111087

    Note that when you run nltk.download(), a window will pop up and let you select which packages to download (Download is not automatically started right away).

    To complement the accepted answer, the following is a complete list of directories that will be searched on Mac (not limited to the one mentioned in the accepted answer): - '/Users/YOUR_USERNAME/nltk_data' - '/usr/share/nltk_data' - '/usr/local/share/nltk_data' - '/usr/lib/nltk_data' - '/usr/local/lib/nltk_data' - '/Users/YOUR_USERNAME/YOUR_VIRTUAL_ENV_DIRECTORY/nltk_data' - '/Users/YOUR_USERNAME/YOUR_VIRTUAL_ENV_DIRECTORY/share/nltk_data' - '/Users/YOUR_USERNAME/YOUR_VIRTUAL_ENV_DIRECTORY/lib/nltk_data'

    In case the link above dies, here is the solution pasted in its entirety:

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

    Run the above code in your favourite Python IDE or via the command line.

    0 讨论(0)
提交回复
热议问题