Patrick C.
Patrick C.

Reputation: 97

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

Upvotes: 4

Views: 21670

Answers (4)

Colin Xu
Colin Xu

Reputation: 23

A simple shutting down and re-start Jupyter Notebook fix my problem.

Upvotes: 0

meliksahturker
meliksahturker

Reputation: 1504

I have encountered with this on Python3.7. I had installed spacy from Jupyter Notebok cell, via !python -m pip install spacy command. Shutting down and re-starting Jupyter Notebook resolved it

Upvotes: 3

Nabin Bhandari
Nabin Bhandari

Reputation: 16409

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

Upvotes: 0

Manoj N D
Manoj N D

Reputation: 67

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.

Upvotes: 5

Related Questions