From 6bec24cdd09c8168d2ce8667e376bb1f0e320c07 Mon Sep 17 00:00:00 2001 From: Ines Montani Date: Wed, 7 Aug 2019 13:18:11 +0200 Subject: [PATCH] Require downloaded model in pkg_resources (#4090) --- spacy/cli/download.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spacy/cli/download.py b/spacy/cli/download.py index 1075b0c60..8a993178a 100644 --- a/spacy/cli/download.py +++ b/spacy/cli/download.py @@ -6,6 +6,7 @@ import requests import os import subprocess import sys +import pkg_resources from wasabi import Printer from .link import link @@ -67,6 +68,16 @@ def download(model, direct=False, *pip_args): "the model via its full package name: " "nlp = spacy.load('{}')".format(model, model_name), ) + # If a model is downloaded and then loaded within the same process, our + # is_package check currently fails, because pkg_resources.working_set + # is not refreshed automatically (see #3923). We're trying to work + # around this here be requiring the package explicitly. + try: + pkg_resources.working_set.require(model_name) + except: # noqa: E722 + # Maybe it's possible to remove this – mostly worried about cross- + # platform and cross-Python copmpatibility here + pass def get_json(url, desc):