Skip to content

Commit

Permalink
Merge pull request #1060 from biolab/fix-gensim-scipy-crash
Browse files Browse the repository at this point in the history
Monkey-patch scipy.linalg.triu for gensim
  • Loading branch information
lanzagar authored Jun 28, 2024
2 parents f73d42f + d2059a5 commit 101f30e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions orangecontrib/text/corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
)
from Orange.preprocess.transformation import Identity
from Orange.data.util import get_unique_names

# Gensim is 4.3.2 is incompatible with scipy 1.3, where they removed triu/
# thus hack what it is missing here it.
# Remove this section after we depend on newer gensim
import scipy.linalg
if "triu" not in scipy.linalg.__dict__:
scipy.linalg.triu = np.triu

from gensim import corpora
from orangewidget.utils.signals import summarize, PartialSummary
import scipy.sparse as sp
Expand Down
12 changes: 12 additions & 0 deletions orangecontrib/text/tests/test_corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@
from orangecontrib.text.tag import AveragedPerceptronTagger


class ImportHack(unittest.TestCase):

def test_perhaps_remove_gensim_hack(self):
now = datetime.now()
if (now.year, now.month) >= (2024, 7):
self.fail(
"Check if gensim newer than 4.3.2 is available; if so, add it "
"to requirements, remove the scipy monkey-patch in corpus.py "
"and this test."
)


class CorpusTests(unittest.TestCase):
def setUp(self):
self.pos_tagger = AveragedPerceptronTagger()
Expand Down

1 comment on commit 101f30e

@tylercaimber
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please dearest Orange Lord, merge this. I have been getting this error when trying to install Text 1.15.0.
I am installing on WSL2 Ubuntu 22.04 LTS (running the GUI through xcfe4 + VNC):

What happens on a fresh conda 3.10 env install:

myhome@mymachine ~ $ conda activate orange3
(orange3) myhome@mymachine ~ $ conda install orange3
...
(orange3) myhome@mymachine ~ $ conda install orange3-text
...
(orange3) myhome@mymachine ~ $ python -m Orange.canvas -l 4
qt.qpa.xcb: XKeyboard extension not present on the X server
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-myhome'
2024-07-04 00:30:57,520:INFO:orangecanvas.registry.base: A category with 'Data' name already exists
2024-07-04 00:30:57,818:INFO:orangecanvas.registry.base: A category with 'Visualize' name already exists
2024-07-04 00:30:57,955:INFO:orangecanvas.registry.discovery: Ignoring '/home/myhome/anaconda3/envs/orange3/lib/python3.10/site-packages/Orange/widgets/visualize/owscatterplotgraph.py'.
2024-07-04 00:30:57,988:INFO:orangecanvas.registry.discovery: Ignoring '/home/myhome/anaconda3/envs/orange3/lib/python3.10/site-packages/Orange/widgets/visualize/owtreeviewer2d.py'.
2024-07-04 00:30:58,007:INFO:orangecanvas.registry.discovery: Ignoring '/home/myhome/anaconda3/envs/orange3/lib/python3.10/site-packages/Orange/widgets/visualize/pythagorastreeviewer.py'.
2024-07-04 00:30:58,011:INFO:orangecanvas.registry.base: A category with 'Model' name already exists
2024-07-04 00:30:58,205:INFO:orangecanvas.registry.base: A category with 'Evaluate' name already exists
2024-07-04 00:30:58,208:INFO:orangecanvas.registry.discovery: Ignoring '/home/myhome/anaconda3/envs/orange3/lib/python3.10/site-packages/Orange/widgets/evaluate/contexthandlers.py'.
2024-07-04 00:30:58,284:INFO:orangecanvas.registry.discovery: Ignoring '/home/myhome/anaconda3/envs/orange3/lib/python3.10/site-packages/Orange/widgets/evaluate/utils.py'.
2024-07-04 00:30:58,287:INFO:orangecanvas.registry.base: A category with 'Unsupervised' name already exists
2024-07-04 00:30:59,733:ERROR:orangecanvas.registry.discovery: An exception occurred while loading entry point 'EntryPoint(name='Text Mining', value='orangecontrib.text.widgets', group='orange.widgets')'
Traceback (most recent call last):
  File "/home/myhome/anaconda3/envs/orange3/lib/python3.10/site-packages/orangecanvas/registry/discovery.py", line 131, in run
    point = entry_point.load()
  File "/home/myhome/anaconda3/envs/orange3/lib/python3.10/importlib/metadata/__init__.py", line 171, in load
    module = import_module(match.group('module'))
  File "/home/myhome/anaconda3/envs/orange3/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/myhome/anaconda3/envs/orange3/lib/python3.10/site-packages/orangecontrib/text/__init__.py", line 8, in <module>
    from .corpus import Corpus
  File "/home/myhome/anaconda3/envs/orange3/lib/python3.10/site-packages/orangecontrib/text/corpus.py", line 22, in <module>
    from gensim import corpora
  File "/home/myhome/anaconda3/envs/orange3/lib/python3.10/site-packages/gensim/__init__.py", line 11, in <module>
    from gensim import parsing, corpora, matutils, interfaces, models, similarities, utils  # noqa:F401
  File "/home/myhome/anaconda3/envs/orange3/lib/python3.10/site-packages/gensim/corpora/__init__.py", line 6, in <module>
    from .indexedcorpus import IndexedCorpus  # noqa:F401 must appear before the other classes
  File "/home/myhome/anaconda3/envs/orange3/lib/python3.10/site-packages/gensim/corpora/indexedcorpus.py", line 14, in <module>
    from gensim import interfaces, utils
  File "/home/myhome/anaconda3/envs/orange3/lib/python3.10/site-packages/gensim/interfaces.py", line 19, in <module>
    from gensim import utils, matutils
  File "/home/myhome/anaconda3/envs/orange3/lib/python3.10/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' (/home/myhome/anaconda3/envs/orange3/lib/python3.10/site-packages/scipy/linalg/__init__.py)
2024-07-04 00:30:59,755:INFO:orangecanvas.main: Switching default stylesheet to darkorange
2024-07-04 00:30:59,758:INFO:orangecanvas.main: Adding search path '__init__.py/orange' for prefix, 'canvas_icons'

What happens when I build Orange-text3 from source:

...
Successfully built Orange3-Text
Installing collected packages: Orange3-Text
Successfully installed Orange3-Text-1.15.0.dev0+101f30e
(orange3) myhome@mymachine ~/orange3-text $

Looks like the monkey patch is workinggg heehee

My condolences that they rugpulled triu

Please sign in to comment.