SSL: CERTIFICATE_VERIFY_FAILED error while downloading python -m spacy download en
Asked Answered
R

7

15

I have downloaded spacy in Anaconda prompt by using conda install -c conda-forge spacy. But when I tried to download en_core_we_sm using python -m spacy download en_core_web_sm I getting SSL: CERTIFICATE_VERIFY_FAILED error. Screen Shot

Ruffi answered 18/4, 2019 at 9:12 Comment(4)
Possible duplicate of pip install fails with "connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:598)"Retarded
No both have different error codes. Mine is (_ssl.c:1056) while the one in the other question is (_ssl.c:598)Ruffi
That's just different line numbers -- it's normal for them to change between different versions of the library; it's still the same underlying problem, with the same solutions.Paratrooper
Does this answer your question? I get CERTIFICATE_VERIFY_FAILED when I try to install the spaCy English language modelIntermix
F
39

With HTTPS, trying to download something from a remote host produces an SSL connection error in some cases like if your computer is behind a proxy which does not let you to make SSL connection freely. For those cases, a downloading manager like pip , conda for python or apt-get or yum for Linux provide some options for a user to specify certificate for such connections or to allow untrusted communication with a remote host for such downloads.

However, downloading a model VIA spacy with python -m spacy download does not provide such options. You cannot add any SSL certificates nor specify trusted host for a download.

Fortunately, there's a workaround solution with two separate steps , downloading and installing. That is, download the model with any other clients which is under control with SSL (browser, curl, wget...) then install the downloaded model with pip install

Find appropriate model you need on https://github.com/explosion/spacy-models/releases and download tar.gz file like,

wget https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.2.5/en_core_web_sm-2.2.5.tar.gz

Then install it like,

python -m pip install ./en_core_web_sm-2.2.5.tar.gz

Frangipani answered 30/1, 2020 at 6:18 Comment(4)
Thanks for this. why is this not an accepted answer!Tum
I got most of the answers nearly after a year of posting this question. By the time I probably skipped this question. And right now I don't recall what I was working on and so can not verify it. If there are many up ticks for the answer then the answer should probably work. Sorry about that!Ruffi
I have had the same issue and this answer has worked for me!Politico
This command helpfully tells you the url of which model to download (taken from spacy.io/usage/models#download-pip): spacy info en_core_web_sm --url. You can then simply download the model's whl file using your web browser.Pleo
S
6

The answer provided by K. Symbol is helpful. As an alternative, the download and installation can be done in one statement with pip. Pip can be assigned "trusted-host" and the "install" object can be a website, so:

pip --trusted-host github.com --trusted-host objects.githubusercontent.com install https://github.com/explosion/spacy-models/releases/download/en_core_web_md-3.4.0/en_core_web_md-3.4.0.tar.gz
Sacerdotalism answered 28/8, 2022 at 15:26 Comment(0)
C
4

Just download the direct version.

python -m spacy download en_core_web_sm-2.2.0 --direct

I had the same error as you, gave this a try, and it worked. For more information here are some additional details from the model page: https://spacy.io/usage/models

Chane answered 25/10, 2020 at 2:34 Comment(0)
S
0

For me the issue was i was running the command "python -m spacy download en" from a different location other than "C:\WINDOWS\system32". When i ran the command from "C:\WINDOWS\system32" with "Run as Admin" it worked like charm. Seems from other locations it is not able to load the correct ssl config.

Sofa answered 13/6, 2019 at 18:51 Comment(0)
P
0

If you are unable to download it because you cannot verify the certificate as you are behind a company proxy, you can also do the following by first downloading the file via requests and specifying that you don't want to check certifictates, then install it via pip:

import requests, os

lang = 'en'
r = requests.get(f'https://github.com/explosion/spacy-models/releases/download/{lang}_core_news_sm-3.0.0/{lang}_core_news_sm-3.0.0-py3-none-any.whl',
                 verify=False)  # verify=False to skip checking of certificate
file = f'{lang}_core_news_sm-3.0.0-py3-none-any.whl'
with open(file,'wb') as output_file:
    output_file.write(r.content)  # save the wheel locally
# then install it via pip
!pip install {file} --user  
os.remove(file)  # remove the file
Parfait answered 1/3, 2021 at 15:59 Comment(0)
L
0

Assuming you have a virtual environment:

First, add the certificates in your local chain, usually located at:

your_folder\venv\Lib\site-packages\certifi\cacert.pem

In Windows concatenate using:

type your_cer.cer >> your_folder\venv\Lib\site-packages\certifi\cacert.pem

Try download manually:

python -m spacy download pt_core_news_lg-3.5.0 --direct --use-feature=truststore

To install packages use:

pip install yourpackage --use-feature=truststore
Loreeloreen answered 26/2 at 17:3 Comment(0)
R
-2

First, Uninstall Spacy and clean the directories. Then install with the following link -

pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org spacy

Use pip3 for Python3 and run following in a terminal

python -m spacy download en_core_web_sm

let me know if you still get error/s. Follow https://spacy.io/usage/models

Retarded answered 22/4, 2019 at 11:46 Comment(3)
This cannot be a solution as the problem caused by disabled SSL connection while downloading spacy model where a user cannot let the download command to trust any host with or without a specific certificates. Reinstalling with the "trusted-host" option does not affect any following SSL requests made after the installation. Also, the link describes nothing about a solution to this problem.Frangipani
Basically that solution worked for me, also trusted host is from pypi.org from where the library will get downloaded.Retarded
@NaitikChandak, if you don't force ssl certificates to be validated, how do you know it's really pypi.org that the download is coming from? Could be some hacker who took over your coffeeshop wifi and is substituting their own code with a bitcoin miner added to the library you want.Paratrooper

© 2022 - 2024 — McMap. All rights reserved.