cannot import name 'triu' from 'scipy.linalg'

3,838 views
Skip to first unread message

Daniel

unread,
Apr 4, 2024, 3:47:16 PMApr 4
to Gensim
Hi, I installed gensim as mentioned in the documentation: 

pip install --upgrade gensim


problem, when I do: 

import gensim

I get: 

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[3], line 1
----> 1 import gensim

File ~/gesim/lib/python3.11/site-packages/gensim/__init__.py:11
      7 __version__ = '4.3.2'
      9 import logging
---> 11 from gensim import parsing, corpora, matutils, interfaces, models, similarities, utils  # noqa:F401
     14 logger = logging.getLogger('gensim')
     15 if not logger.handlers:  # To ensure reload() doesn't add another one

File ~/gesim/lib/python3.11/site-packages/gensim/corpora/__init__.py:6
      1 """
      2 This package contains implementations of various streaming corpus I/O format.
      3 """
      5 # bring corpus classes directly into package namespace, to save some typing
----> 6 from .indexedcorpus import IndexedCorpus  # noqa:F401 must appear before the other classes
      8 from .mmcorpus import MmCorpus  # noqa:F401
      9 from .bleicorpus import BleiCorpus  # noqa:F401

File ~/gesim/lib/python3.11/site-packages/gensim/corpora/indexedcorpus.py:14
     10 import logging
     12 import numpy
---> 14 from gensim import interfaces, utils
...
---> 20 from scipy.linalg import get_blas_funcs, triu
     21 from scipy.linalg.lapack import get_lapack_funcs
     22 from scipy.special import psi  # gamma function utils

ImportError: cannot import name 'triu' from 'scipy.linalg' (/Users/danielmoreno/gesim/lib/python3.11/site-packages/scipy/linalg/__init__.py)


output of pip freeze: 

appnope==0.1.4
asttokens==2.4.1
comm==0.2.2
debugpy==1.8.1
decorator==5.1.1
executing==2.0.1
gensim==4.3.2
ipykernel==6.29.4
ipython==8.23.0
jedi==0.19.1
jupyter_client==8.6.1
jupyter_core==5.7.2
matplotlib-inline==0.1.6
nest-asyncio==1.6.0
numpy==1.26.4
packaging==24.0
parso==0.8.3
pexpect==4.9.0
platformdirs==4.2.0
prompt-toolkit==3.0.43
psutil==5.9.8
ptyprocess==0.7.0
pure-eval==0.2.2
Pygments==2.17.2
python-dateutil==2.9.0.post0
pyzmq==25.1.2
scipy==1.13.0
six==1.16.0
smart-open==7.0.4
stack-data==0.6.3
tornado==6.4
traitlets==5.14.2
typing_extensions==4.10.0
wcwidth==0.2.13
wrapt==1.16.0

python version: python3 --version
Python 3.11.7


How can I fix the error??

Thank you in advance

Gordon Mohr

unread,
Apr 10, 2024, 12:04:04 PMApr 10
to Gensim
Scipy recently removed these functions after a fairly brief (less than 1 year) 'deprecation' warning period. The easiest workaround for now is to use scipy 1.12 rather than the very-lates: `pip install scipy==1.12`.

(The simple fix for this in Gensim has already been applied in source code and the next public release of Gensim won't require such a workaround – see issue https://github.com/piskvorky/gensim/issues/3525 )

- Gordon

Reply all
Reply to author
Forward
0 new messages