explosion / spaCy

💫 Industrial-strength Natural Language Processing (NLP) in Python
https://spacy.io
MIT License
29.71k stars 4.36k forks source link

ImportError: cannot import name symnols #13547

Closed fschlz closed 2 months ago

fschlz commented 2 months ago

How to reproduce the behaviour

trying to import Corpus or Example as shown here: https://spacy.io/usage/training#custom-code-readers-batchers

from spacy.training import Corpus

produces import error:

---------------------------------------------------------------------------
ImportError
Traceback (most recent call last)
Cell In[3], line 1
----> 1 from spacy.training import Corpus

File ~/dev/project/.venv/lib/python3.10/site-packages/spacy/__init__.py:13
     10 # These are imported as part of the API
     11 from thinc.api import Config, prefer_gpu, require_cpu, require_gpu  # noqa: F401
---> 13 from . import pipeline  # noqa: F401
     14 from . import util
     15 from .about import __version__  # noqa: F401

File ~/dev/project/.venv/lib/python3.10/site-packages/spacy/pipeline/__init__.py:1
----> 1 from .attributeruler import AttributeRuler
      2 from .dep_parser import DependencyParser
      3 from .edit_tree_lemmatizer import EditTreeLemmatizer

File ~/dev/project/.venv/lib/python3.10/site-packages/spacy/pipeline/attributeruler.py:8
      6 from .. import util
      7 from ..errors import Errors
----> 8 from ..language import Language
      9 from ..matcher import Matcher
     10 from ..scorer import Scorer

File ~/dev/project/.venv/lib/python3.10/site-packages/spacy/language.py:43
     41 from .lang.tokenizer_exceptions import BASE_EXCEPTIONS, URL_MATCH
     42 from .lookups import load_lookups
---> 43 from .pipe_analysis import analyze_pipes, print_pipe_analysis, validate_attrs
     44 from .schemas import (
     45     ConfigSchema,
     46     ConfigSchemaInit,
   (...)
     49     validate_init_settings,
     50 )
     51 from .scorer import Scorer

File ~/dev/project/.venv/lib/python3.10/site-packages/spacy/pipe_analysis.py:6
      3 from wasabi import msg
      5 from .errors import Errors
----> 6 from .tokens import Doc, Span, Token
      7 from .util import dot_to_dict
      9 if TYPE_CHECKING:
     10     # This lets us add type hints for mypy etc. without causing circular imports

File ~/dev/project/.venv/lib/python3.10/site-packages/spacy/tokens/__init__.py:1
----> 1 from ._serialize import DocBin
      2 from .doc import Doc
      3 from .morphanalysis import MorphAnalysis

File ~/dev/project/.venv/lib/python3.10/site-packages/spacy/tokens/_serialize.py:14
     12 from ..errors import Errors
     13 from ..util import SimpleFrozenList, ensure_path
---> 14 from ..vocab import Vocab
     15 from ._dict_proxies import SpanGroups
     16 from .doc import DOCBIN_ALL_ATTRS as ALL_ATTRS

File ~/dev/project/.venv/lib/python3.10/site-packages/spacy/vocab.pyx:1, in init spacy.vocab()

File ~/dev/project/.venv/lib/python3.10/site-packages/spacy/morphology.pyx:9, in init spacy.morphology()

ImportError: cannot import name symbols

I'm not sure why there are dots being used to navigate the submodules instead of the full module path. i.e. from . import pipeline opposed to from spacy import pipeline

Your Environment

fschlz commented 2 months ago

I reinstalled spacy and it magically solved the issue

github-actions[bot] commented 1 month ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.