pythonpipconcatenationspacychatterbot

Download model 'en' for spacy produces "TypeError: can only concatenate list (not 'tuple') to list"


While installing spacy-2.3.6 after chatterbot-1.0.8 in virtualenv-20.19.0 with python-3.7.0, I receive error message

OSError: [E050] Can't find model 'en'. It doesn't seem to be a shortcut link,
a Python package or a valid path to a data directory

Following suggestion from here as

spacy.cli.download("en")
nlp = spacy.load('en_core_web_sm')

and from here as

python -m spacy download en_core_web_md
python -m spacy link en_core_web_md en

do not solved the problem, but produce other error message

[..]
  File "C:\venvs\chatterbot\lib\site-packages\spacy\cli\download.py", line 132,
    in download_model cmd = [sys.executable, "-m", "pip", "install"]
    + pip_args + [download_url]
TypeError: can only concatenate list (not "tuple") to list

whose normally in user program as in here, here, and here, but in my case is in the download.py file.

I modify the file as follow

def download_model(filename, user_pip_args=None):
    download_url = about.__download_url__ + "/" + filename
    pip_args = user_pip_args if user_pip_args is not None else []
    #cmd = [sys.executable, "-m", "pip", "install"] + pip_args + [download_url]
    cmd = [sys.executable, "-m", "pip", "install"] + list(pip_args) + [download_url]
    return subprocess.call(cmd, env=os.environ.copy())

and it works.

[..]
Collecting en_core_web_sm==2.3.1
[..]
āœ” Download and installation successful
You can now load the model via spacy.load('en_core_web_sm')
symbolic link created for C:\venvs\chatterbot\lib\site-packages\spacy\data\en
<<===>> C:\venvs\chatterbot\lib\site-packages\en_core_web_sm
āœ” Linking successful
C:\venvs\chatterbot\lib\site-packages\en_core_web_sm -->
C:\venvs\chatterbot\lib\site-packages\spacy\data\en
You can now load the model via spacy.load('en')

The questions are


Solution

  • One solution is to use the newest v2.3 release (currently v2.3.9), since v2.3.7+ includes a fix for this bug.

    The other option is to specify the package directly instead of using spacy download. For example, your requirements could include:

    https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.3.1/en_core_web_sm-2.3.1.tar.gz#egg=en_core_web_sm
    

    See: https://v2.spacy.io/usage/models#models-download