cisocrgroup/ocrd_cis

remove unconditional pylab imports

Closed this issue · 0 comments

It looks like the package python3-tk should be added to the list of required packages. Without it, I got this error:

(venv-20200906) $ ocrd-cis-ocropy-denoise --help
Traceback (most recent call last):
  File "/usr/lib/python3.5/tkinter/__init__.py", line 36, in <module>
    import _tkinter
ImportError: No module named '_tkinter'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/venv-20200906/bin/ocrd-cis-ocropy-denoise", line 5, in <module>
    from ocrd_cis.ocropy.cli import ocrd_cis_ocropy_denoise
  File "/venv-20200906/lib/python3.5/site-packages/ocrd_cis/ocropy/cli.py", line 4, in <module>
    from ocrd_cis.ocropy.binarize import OcropyBinarize
  File "/venv-20200906/lib/python3.5/site-packages/ocrd_cis/ocropy/binarize.py", line 25, in <module>
    from . import common
  File "/venv-20200906/lib/python3.5/site-packages/ocrd_cis/ocropy/common.py", line 12, in <module>
    from . import ocrolib
  File "/venv-20200906/lib/python3.5/site-packages/ocrd_cis/ocropy/ocrolib/__init__.py", line 11, in <module>
    from . import default, common
  File "/venv-20200906/lib/python3.5/site-packages/ocrd_cis/ocropy/ocrolib/common.py", line 22, in <module>
    from pylab import (clf, cm, ginput, gray, imshow, ion, subplot,
  File "/venv-20200906/lib/python3.5/site-packages/pylab.py", line 1, in <module>
    from matplotlib.pylab import *
  File "/venv-20200906/lib/python3.5/site-packages/matplotlib/pylab.py", line 245, in <module>
    from matplotlib import cbook, mlab, pyplot as plt
  File "/venv-20200906/lib/python3.5/site-packages/matplotlib/pyplot.py", line 2372, in <module>
    switch_backend(rcParams["backend"])
  File "/venv-20200906/lib/python3.5/site-packages/matplotlib/pyplot.py", line 207, in switch_backend
    backend_mod = importlib.import_module(backend_name)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/venv-20200906/lib/python3.5/site-packages/matplotlib/backends/backend_tkagg.py", line 1, in <module>
    from . import _backend_tk
  File "/venv-20200906/lib/python3.5/site-packages/matplotlib/backends/_backend_tk.py", line 5, in <module>
    import tkinter as Tk
  File "/usr/lib/python3.5/tkinter/__init__.py", line 38, in <module>
    raise ImportError(str(msg) + ', please install the python3-tk package')
ImportError: No module named '_tkinter', please install the python3-tk package

@stweil Thanks for the report. I am surprised we did not detect this earlier. It is another example of bad ocrolib packaging – these show/plot functions are not needed usually, so the pylab import should not be unconditional (but function-local).

I don't think we should allow dragging in python3-tk (which in turn requires X11 libs).

Originally posted in OCR-D/ocrd_all#184 (comment)