pythonjupyter-notebookspacyhuggingface-transformersgensim

SpaCy and Gensim on Jupyter Notebooks


I have bought a new macbook and have installed python 3.12.5 on it. I am trying to import and run libraries for Natural Langauge Processing in a Jupyter Notebook, and all is well... except when it comes to spaCy and gensim.

import spacy
import gensim
TypeError: ForwardRef._evaluate() missing 1 required keyword-only argument: 'recursive_guard'

I checked to see if they are imported with :

!pip show spacy
!pip show gensim

Name: spacy
Version: 3.7.5
Summary: Industrial-strength Natural Language Processing (NLP) in Python
Home-page: https://spacy.io
Author: Explosion
Author-email: contact@explosion.ai
License: MIT
Location: /opt/anaconda3/lib/python3.12/site-packages
Requires: catalogue, cymem, jinja2, langcodes, murmurhash, numpy, packaging, preshed, pydantic, requests, setuptools, spacy-legacy, spacy-loggers, srsly, thinc, tqdm, typer, wasabi, weasel
Required-by: 
Name: gensim
Version: 4.3.2
Summary: Python framework for fast Vector Space Modelling
Home-page: https://radimrehurek.com/gensim/
Author: Radim Rehurek
Author-email: me@radimrehurek.com
License: LGPL-2.1-only
Location: /opt/anaconda3/lib/python3.12/site-packages
Requires: numpy, scipy, smart-open
Required-by: 

So they should be loaded, but I don't know what the TypeError refers to and how to fix it!

I read that there is something with the python update...but could anyone help me clarify this?


Solution

  • Problem occurs in pydantic library (to be exact pydantic.v1.typing module) the best solution at the moment is to downgrade python version to 3.12.3. Patches to this problem has been already merged to repository but you need to wait for next release.