简体   繁体   中英

Import Spacy Error "cannot import name dataclass_transform"

I am working on a jupyter notebook project which should use spacy. I already used pip install to install spacy in anaconda prompt.

However, when I tried to import spacy, it gives me the follwing error.

I wonder what the problem is and what I can do to solve that.

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-96-3173a3034708> in <module>
      9 #nltk.download()
     10 from nltk.corpus import stopwords
---> 11 import spacy
     12 
     13 #path where we store the txt files

D:\Python\lib\site-packages\spacy\__init__.py in <module>
      4 
      5 # set library-specific custom warning handling before doing anything else
----> 6 from .errors import setup_default_warnings
      7 
      8 setup_default_warnings()  # noqa: E402

D:\Python\lib\site-packages\spacy\errors.py in <module>
      1 import warnings
----> 2 from .compat import Literal
      3 
      4 
      5 class ErrorsWithCodes(type):

D:\Python\lib\site-packages\spacy\compat.py in <module>
      1 """Helpers for Python and platform compatibility."""
      2 import sys
----> 3 from thinc.util import copy_array
      4 
      5 try:

D:\Python\lib\site-packages\thinc\util.py in <module>
      6 import functools
      7 from wasabi import table
----> 8 from pydantic import create_model, ValidationError
      9 import inspect
     10 import os

D:\Python\lib\site-packages\pydantic\__init__.cp38-win_amd64.pyd in init pydantic.__init__()

D:\Python\lib\site-packages\pydantic\dataclasses.cp38-win_amd64.pyd in init pydantic.dataclasses()

ImportError: cannot import name dataclass_transform

You can try following codes:

pip install -U pip setuptools wheel
pip install -U spacy
python -m spacy download en_core_web_sm

After installation restart the kernal if you are using Jupyter notebook or lab.

It does works for my end.

I am using Windows with Anaconda virtual environment. Uninstalling spacy from pip and installing it from conda did the job for me.

pip uninstall spacy
conda install spacy
python -m spacy download en_core_web_sm --user

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM