flair
flair copied to clipboard
ImportError: cannot import name 'triu' from 'scipy.linalg'[Question]:
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.
already having this issue too
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"
How can this simple issue not be fixed yet? It seems that changing the import to from numpy import triu fixes everything.
@MatrixRanger98 as noted on the comment above, this is fixed but gensim didn't release it already.
https://stackoverflow.com/a/78555609/13086128
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
still observing this issue on latest python 3.10 builds
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.