flair icon indicating copy to clipboard operation
flair copied to clipboard

ImportError: cannot import name 'triu' from 'scipy.linalg'[Question]:

Open Sritharan-racap opened this issue 1 year ago • 8 comments

Question

All of a sudden I'm getting this error. please help. I did pip install flair

 File "/Users/smahendra/opt/anaconda3/envs/gpt11/lib/python3.11/site-packages/flair/embeddings/document.py", line 16, in <module>
    from flair.embeddings.token import FlairEmbeddings, StackedEmbeddings, TokenEmbeddings
  File "/Users/smahendra/opt/anaconda3/envs/gpt11/lib/python3.11/site-packages/flair/embeddings/token.py", line 10, in <module>
    import gensim
  File "/Users/smahendra/opt/anaconda3/envs/gpt11/lib/python3.11/site-packages/gensim/__init__.py", line 11, in <module>
    from gensim import parsing, corpora, matutils, interfaces, models, similarities, utils  # noqa:F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/smahendra/opt/anaconda3/envs/gpt11/lib/python3.11/site-packages/gensim/corpora/__init__.py", line 6, in <module>
    from .indexedcorpus import IndexedCorpus  # noqa:F401 must appear before the other classes
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/smahendra/opt/anaconda3/envs/gpt11/lib/python3.11/site-packages/gensim/corpora/indexedcorpus.py", line 14, in <module>
    from gensim import interfaces, utils
  File "/Users/smahendra/opt/anaconda3/envs/gpt11/lib/python3.11/site-packages/gensim/interfaces.py", line 19, in <module>
    from gensim import utils, matutils
  File "/Users/smahendra/opt/anaconda3/envs/gpt11/lib/python3.11/site-packages/gensim/matutils.py", line 20, in <module>
    from scipy.linalg import get_blas_funcs, triu
ImportError: cannot import name 'triu' from 'scipy.linalg' (/Users/smahendra/opt/anaconda3/envs/gpt11/lib/python3.11/site-packages/scipy/linalg/__init__.py)

Update: flair is importing gensim which is importing scipy. On April-2-24, scipy removed the triu from linalg module. from flair.data import Sentence is failing. As it is a key component, pretty much all of flair code in our project is failing.

Sritharan-racap avatar Apr 04 '24 14:04 Sritharan-racap

already having this issue too

PrettyBoyHelios avatar Apr 04 '24 17:04 PrettyBoyHelios

Hi all,

Gensim is aware of this issue and already merged their patch, see https://github.com/piskvorky/gensim/issues/3525

As long as they haven't released, I suggest you follow their hotfix of pinning scipy = "<1.13.0"

helpmefindaname avatar Apr 05 '24 11:04 helpmefindaname

How can this simple issue not be fixed yet? It seems that changing the import to from numpy import triu fixes everything.

MatrixRanger98 avatar May 06 '24 19:05 MatrixRanger98

@MatrixRanger98 as noted on the comment above, this is fixed but gensim didn't release it already.

helpmefindaname avatar May 06 '24 22:05 helpmefindaname

https://stackoverflow.com/a/78555609/13086128

RubTalha avatar May 30 '24 15:05 RubTalha

Well yes but if you don't want other packages to be affected, it is neater to install the develop branch of gensim:

pip install git+https://github.com/piskvorky/gensim.git@develop

MatrixRanger98 avatar May 30 '24 15:05 MatrixRanger98

still observing this issue on latest python 3.10 builds

cobycloud avatar Jun 17 '24 08:06 cobycloud

Yeah @cobycloud it wont be properly "fixed" until the next version of gensim is uploaded to PyPI. Ideally imo they would either have fixed this ages ago when scipy first deprecated triu, or at the very least pushed out a single patch of the current version, but instead they've added the fix to the list of things that will make it into the next release whenever that is.

david-waterworth avatar Jul 04 '24 05:07 david-waterworth