我看到了关于这个主题的其他问题,但没有一个能解决我的问题。我还没有在它的默认位置“c:\anaconda3”安装 anaconda,而且我正在使用 VSCode 进行开发。当我运行我的代码时,这非常简单
import spacy
nlp = spacy.load("en_core_web_sm")
doc = nlp("Apple is looking at buying U.K. startup for $1 billion")
for token in doc:
print(token.text, token.pos_, token.dep_)
我收到错误(下面最后列出)。作为新手,我不知道从哪里开始。请指教...
资料:
(base) C:\Users\ashish>conda info
active environment : base
active env location : c:\Software\Installed\anaconda3
shell level : 2
user config file : C:\Users\ashish\.condarc
populated config files : C:\Users\ashish\.condarc
conda version : 4.8.2
conda-build version : 3.18.11
python version : 3.7.6.final.0
virtual packages :
base environment : c:\Software\Installed\anaconda3 (writable)
channel URLs : https://repo.anaconda.com/pkgs/main/win-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/r/win-64
https://repo.anaconda.com/pkgs/r/noarch
https://repo.anaconda.com/pkgs/msys2/win-64
https://repo.anaconda.com/pkgs/msys2/noarch
package cache : c:\Software\Installed\anaconda3\pkgs
C:\Users\ashish\.conda\pkgs
C:\Users\ashish\AppData\Local\conda\conda\pkgs
envs directories : c:\Software\Installed\anaconda3\envs
C:\Users\ashish\.conda\envs
C:\Users\ashish\AppData\Local\conda\conda\envs
platform : win-64
user-agent : conda/4.8.2 requests/2.22.0 CPython/3.7.6 Windows/10 Windows/10.0.17134
administrator : False
netrc file : None
offline mode : False
我正在使用 VSCode,当我尝试从内置终端转到 python 提示符时,出现以下错误
C:\Projects\Internal Data Mining>python
Python 3.7.6 (default, Jan 8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated. Libraries may fail to load. To activate this environment
please see https://conda.io/activation
Type "help", "copyright", "credits" or "license" for more information.
虽然从 conda 提示我已经激活了 'base'
我安装了 Spacy 和 en_core_web_sm,en_core_web_lg 包信息如下:
spacy 2.0.12 py37h8300f20_0
spacy-model-en_core_web_lg 2.2.5 py_0 conda-forge
spacy-model-en_core_web_sm 2.2.5 py_0 conda-forge
主要错误:
[Running] python -u "c:\Projects\Internal Data Mining\SpacyTutorial.py"
Traceback (most recent call last):
File "c:\Projects\Internal Data Mining\SpacyTutorial.py", line 16, in <module>
nlp = spacy.load("en_core_web_sm")
File "C:\Software\Installed\anaconda3\lib\site-packages\spacy\__init__.py", line 15, in load
return util.load_model(name, **overrides)
File "C:\Software\Installed\anaconda3\lib\site-packages\spacy\util.py", line 114, in load_model
return load_model_from_package(name, **overrides)
File "C:\Software\Installed\anaconda3\lib\site-packages\spacy\util.py", line 135, in load_model_from_package
return cls.load(**overrides)
File "C:\Software\Installed\anaconda3\lib\site-packages\en_core_web_sm\__init__.py", line 12, in load
return load_model_from_init_py(__file__, **overrides)
File "C:\Software\Installed\anaconda3\lib\site-packages\spacy\util.py", line 173, in load_model_from_init_py
return load_model_from_path(data_path, meta, **overrides)
File "C:\Software\Installed\anaconda3\lib\site-packages\spacy\util.py", line 156, in load_model_from_path
return nlp.from_disk(model_path)
File "C:\Software\Installed\anaconda3\lib\site-packages\spacy\language.py", line 653, in from_disk
util.from_disk(path, deserializers, exclude)
File "C:\Software\Installed\anaconda3\lib\site-packages\spacy\util.py", line 511, in from_disk
reader(path / key)
File "C:\Software\Installed\anaconda3\lib\site-packages\spacy\language.py", line 649, in <lambda>
deserializers[name] = lambda p, proc=proc: proc.from_disk(p, vocab=False)
File "pipeline.pyx", line 643, in spacy.pipeline.Tagger.from_disk
File "C:\Software\Installed\anaconda3\lib\site-packages\spacy\util.py", line 511, in from_disk
reader(path / key)
File "pipeline.pyx", line 632, in spacy.pipeline.Tagger.from_disk.load_tag_map
File "morphology.pyx", line 56, in spacy.morphology.Morphology.__init__
File "attrs.pyx", line 147, in spacy.attrs.intify_attrs
KeyError: 'PUNCTSIDE_FIN'