gensim clash with numpy 2.x.x

89 views
Skip to first unread message

Dimitar Kazakov

unread,
Mar 25, 2025, 6:33:41 PMMar 25
to Gensim
Hello,

When I try to run Word2Vec on Google Colab, code that was running fine a few days ago now throws an error:

No module named 'numpy.strings'

I have managed to upload gensim with numpy 1.24.4, but have not tested it extensively. Do you currently recommend any particular version of numpy that should be expected to run gensim in a robust way?  Should we expect an update that would get it to work with numpy 2.x.x ?

Many thanks!

Dimitar Kazakov 
University of York, UK

!pip install numpy==1.24.4
!pip install gensim
from gensim import downloader as api
wv = api.load('word2vec-google-news-300')

Gordon Mohr

unread,
Mar 25, 2025, 6:46:52 PMMar 25
to Gensim
Apologies for the delay in approving your post; Google's spam-filtering on Google Groups was recently letting through lots of junk, so new poster approval-gating was enabled – but it sometimes takes me a few days to check the 'pending' area. 

Something definitely changed at Colab in the last week or two, causing a lot of similar errors. But see <https://github.com/piskvorky/gensim/issues/3605#issuecomment-2741244389> for discussion & a workaround. Specifically:

(1) You shouldn't need to specify any version of `numpy` at all, in that installing Gensim should pull in a compatible version (which may, & recently on Colab does, *downgrade* any existing too-new `numpy`)

(2) Your pip command may work OK; another option that seems to get the latest Gensim (& do necessary other-package adjustments) is `!pip install --upgrade gensim`. But: you should force a restart of the backend interpreter after changing packages that it may already have loaded. The Notebook menu pick "Runtime -> Restart session" should do the trick. 

(3) These changes will stay for a while, but if (hours/days later) you revisit the notebook, and the backend has started fresh, you'll need to repeat the `pip` install & session-restart.

A while back when I used Colab, I thought that it hadn't preloaded `numpy` (etc) – so that changing the `numpy` wasn't a problem, the next first load would work fine. But maybe that changed recently. 

Also, I recall it showing a big warning when it noticed you'd done something that disturbed loaded packages. But maybe that went away, too. 

- Gordon
Reply all
Reply to author
Forward
0 new messages