如何修复Spacy中英文加载错误

2024-09-27 21:28:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我用的是水蟒Spyder

我安装了Spacy

conda install -c conda-forge spacy

看起来不错

我现在尝试安装英语

我曾经

python -m spacy download en

python -m spacy download en_core_web_md

python -m spacy download en_core_web_lg

我得到了这个结果

Collecting en_core_web_lg==2.1.0 from https://github.com/explosion/spacy-models/releases/download/en_core_web_lg-2.1.0/en_core_web_lg-2.1.0.tar.gz#egg=en_core_web_lg==2.1.0
  Downloading https://github.com/explosion/spacy-models/releases/download/en_core_web_lg-2.1.0/en_core_web_lg-2.1.0.tar.gz (826.9MB)
    100% |████████████████████████████████| 826.9MB 3.6MB/s
Installing collected packages: en-core-web-lg
  Running setup.py install for en-core-web-lg ... done
Successfully installed en-core-web-lg-2.1.0
✔ Download and installation successful
You can now load the model via spacy.load('en_core_web_lg')

但是当我尝试使用

import spacy
spacy.load("en")

我得到这个错误

runfile('C:/Users/User/OneDrive/__PhD/Code/NLP/NLP02/NLP02.py', wdir='C:/Users/User/OneDrive/__PhD/Code/NLP/NLP02')
Traceback (most recent call last):

  File "<ipython-input-6-ae15dd4e45dd>", line 1, in <module>
    runfile('C:/Users/User/OneDrive/__PhD/Code/NLP/NLP02/NLP02.py', wdir='C:/Users/User/OneDrive/__PhD/Code/NLP/NLP02')

  File "C:\Users\User\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 786, in runfile
    execfile(filename, namespace)

  File "C:\Users\User\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/User/OneDrive/__PhD/Code/NLP/NLP02/NLP02.py", line 2, in <module>
    spacy.load("en")

  File "C:\Users\User\Anaconda3\lib\site-packages\spacy\__init__.py", line 27, in load
    return util.load_model(name, **overrides)

  File "C:\Users\User\Anaconda3\lib\site-packages\spacy\util.py", line 139, in load_model
    raise IOError(Errors.E050.format(name=name))

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.

通过使用

import spacy
spacy.load("en_core_web_lg")

我得到这个错误

runfile('C:/Users/User/OneDrive/__PhD/Code/NLP/NLP02/NLP02.py', wdir='C:/Users/User/OneDrive/__PhD/Code/NLP/NLP02')
Traceback (most recent call last):

  File "<ipython-input-9-ae15dd4e45dd>", line 1, in <module>
    runfile('C:/Users/User/OneDrive/__PhD/Code/NLP/NLP02/NLP02.py', wdir='C:/Users/User/OneDrive/__PhD/Code/NLP/NLP02')

  File "C:\Users\User\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 786, in runfile
    execfile(filename, namespace)

  File "C:\Users\User\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/User/OneDrive/__PhD/Code/NLP/NLP02/NLP02.py", line 2, in <module>
    spacy.load("en_core_web_lg")

  File "C:\Users\User\Anaconda3\lib\site-packages\spacy\__init__.py", line 27, in load
    return util.load_model(name, **overrides)

  File "C:\Users\User\Anaconda3\lib\site-packages\spacy\util.py", line 139, in load_model
    raise IOError(Errors.E050.format(name=name))

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

如何修复这些错误,以便我可以开始使用Spacy


Tags: inpycorewebspacylineloadonedrive

热门问题