flairNLP / flair

A very simple framework for state-of-the-art Natural Language Processing (NLP)
https://flairnlp.github.io/flair/
Other
13.7k stars 2.08k forks source link

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

Open Sritharan-racap opened 2 months ago

Sritharan-racap commented 2 months ago

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.

PrettyBoyHelios commented 2 months ago

already having this issue too

helpmefindaname commented 2 months ago

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"

MatrixRanger98 commented 1 month ago

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

helpmefindaname commented 1 month ago

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

RubTalha commented 1 month ago

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

MatrixRanger98 commented 1 month ago

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
cobycloud commented 2 weeks ago

still observing this issue on latest python 3.10 builds