termux / termux-packages

A package build system for Termux.
https://termux.dev
Other
13.3k stars 3.06k forks source link

[Bug]: matplot lib issues RuntimeError: the sip module implements API v12.0 to v12.12 but the PyQt5.QtCore module requires API v12.13, after installing opencv with GUI support #19755

Closed Coderx7 closed 6 months ago

Coderx7 commented 7 months ago

Problem description

After installing the Opencv package with GUI support Link, I noticed the matplotlib now fails with the following error:

RuntimeError: the sip module implements API v12.0 to v12.12 but the PyQt5.QtCore module requires API v12.13

Heres the full error log :

~/opencv-projects $ python basic_opencv_1_\(roi_splitting_merging_basics\).py
pixel values in a color image at (100,100): [197 122   0]
the blue channel pixel value at (100,100): 197
setting values at (100,100) to all white: [255 255 255]
item at (10,10,2): 1
item value at (10,10,2) after being set: 100
img shape: (1200, 1920, 3)
img pixel count: 6912000
img datatype: uint8
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/data/data/com.termux/files/usr/tmp/runtime-u0_a259'
Traceback (most recent call last):
  File "/storage/emulated/0/Documents/Opencv/OpenCVProjects/basic_opencv_1_(roi_splitting_merging_basics).py", line 116, in <module>
    plt.subplot(231),plt.imshow(img1,'gray'),plt.title('ORIGINAL')
    ^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/matplotlib/pyplot.py", line 1437, in subplot
    fig = gcf()
          ^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/matplotlib/pyplot.py", line 1000, in gcf
    return figure()
           ^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/matplotlib/pyplot.py", line 934, in figure
    manager = new_figure_manager(
              ^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/matplotlib/pyplot.py", line 464, in new_figure_manager
    _warn_if_gui_out_of_main_thread()
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/matplotlib/pyplot.py", line 441, in _warn_if_gui_out_of_main_thread
    canvas_class = cast(type[FigureCanvasBase], _get_backend_mod().FigureCanvas)
                                                ^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/matplotlib/pyplot.py", line 280, in _get_backend_mod
    switch_backend(rcParams._get("backend"))  # type: ignore[attr-defined]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/matplotlib/pyplot.py", line 327, in switch_backend
    switch_backend(candidate)
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/matplotlib/pyplot.py", line 342, in switch_backend
    module = importlib.import_module(cbook._backend_module_name(newbackend))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/matplotlib/backends/backend_qtagg.py", line 9, in <module>
    from .qt_compat import QT_API, QtCore, QtGui
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/matplotlib/backends/qt_compat.py", line 128, in <module>
    _setup()
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/matplotlib/backends/qt_compat.py", line 90, in _setup_pyqt5plus
    from PyQt5 import QtCore, QtGui, QtWidgets
RuntimeError: the sip module implements API v12.0 to v12.12 but the PyQt5.QtCore module requires API v12.13
~/opencv-projects $

What steps will reproduce the bug?

Install matplotlib Install the latest opencv with GUI support from https://github.com/termux/termux-packages/issues/17542#issuecomment-2052370841 run something like this:

import cv2
import numpy as np
import matplotlib.pyplot as plt

# create a simple image
image = np.kron([[1, 0] * 4, [0, 1] * 4] * 4, np.ones((50, 50))).astype(np.uint8) * 255
# Test opencv 
cv2.imshow('checkboard',image)
# wait for 500 ms or a keypress to continue 
# 0 means wait indefinitely until a key is pressed
cv2.waitKey(500)
# Test matplotlib
plt.imshow(image)
plt.show()

What is the expected behavior?

It should run well without any issues.

System information

termux-info:

~ $ termux-info
Termux Variables:
TERMUX_APK_RELEASE=GITHUB
TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_APP_PID=5862
TERMUX_IS_DEBUGGABLE_BUILD=1
TERMUX_MAIN_PACKAGE_FORMAT=debian
TERMUX_VERSION=0.118.0
TERMUX__USER_ID=0
Packages CPU architecture:
aarch64
Subscribed repositories:
# sources.list
deb https://plug-mirror.rcac.purdue.edu/termux/termux-main stable main
# sources.list.d/pointless.list
deb https://its-pointless.github.io/files/21 termux extras
# root-repo (sources.list.d/root.list)
deb https://plug-mirror.rcac.purdue.edu/termux/termux-root root stable
# x11-repo (sources.list.d/x11.list)
deb https://plug-mirror.rcac.purdue.edu/termux/termux-x11 x11 main
# tur-repo (sources.list.d/tur.list)
deb https://tur.kcubeterm.com tur-packages tur tur-on-device tur-continuous
Updatable packages:
bash-completion/stable 2.13.0 all [upgradable from: 2.12.0]
c-ares/stable 1.28.1 aarch64 [upgradable from: 1.28.0]
ca-certificates/stable 1:2024.03.11-2 all [upgradable from: 1:2024.03.11]
clang/stable 18.1.3 aarch64 [upgradable from: 18.1.2]
cmake/stable 3.29.2 aarch64 [upgradable from: 3.29.0]
command-not-found/stable 2.4.0-19 aarch64 [upgradable from: 2.4.0-17]
golang/stable 3:1.22.2 aarch64 [upgradable from: 3:1.22.1]
gst-plugins-bad/stable 1.24.2 aarch64 [upgradable from: 1.24.1]
gst-plugins-base/stable 1.24.2 aarch64 [upgradable from: 1.24.1]
gstreamer/stable 1.24.2 aarch64 [upgradable from: 1.24.1]
libandroid-utimes/stable 0.4 aarch64 [upgradable from: 0.2]
libarchive/stable 3.7.3 aarch64 [upgradable from: 3.7.2]
libcap-ng/stable 2:0.8.5 aarch64 [upgradable from: 2:0.8.4]
libcompiler-rt/stable 18.1.3 aarch64 [upgradable from: 18.1.2]
libjasper/stable 4.2.3 aarch64 [upgradable from: 4.2.2]
libllvm/stable 18.1.3 aarch64 [upgradable from: 18.1.2]
libnghttp2/stable 1.61.0 aarch64 [upgradable from: 1.60.0]
libopenblas/stable 0.3.27 aarch64 [upgradable from: 0.3.26]
libtreesitter/stable 0.22.4 aarch64 [upgradable from: 0.22.2]
libwebp/stable 1.4.0-rc1-0 aarch64 [upgradable from: 1.3.2]
libx11/stable 1.8.9 aarch64 [upgradable from: 1.8.8]
lld/stable 18.1.3 aarch64 [upgradable from: 18.1.2]
llvm/stable 18.1.3 aarch64 [upgradable from: 18.1.2]
matplotlib/stable 3.8.4 aarch64 [upgradable from: 3.8.3]
mesa/stable 24.0.5 aarch64 [upgradable from: 24.0.4]
mpg123/stable 1.32.6 aarch64 [upgradable from: 1.32.5]
ndk-sysroot/stable 26b-3 aarch64 [upgradable from: 26b-2]
python-pandas/tur-packages 2.2.2 aarch64 [upgradable from: 2.2.1]
python-pillow/stable 10.3.0 aarch64 [upgradable from: 10.2.0-1]
termux-keyring/stable 3.11-1 all [upgradable from: 3.11]
termux-tools/stable 1.42.0 all [upgradable from: 1.41.2]
xorg-xauth/x11 1.1.3 aarch64 [upgradable from: 1.1.2]
termux-tools version:
1.41.2
Android version:
11
Kernel build information:
Linux localhost 4.14.180-perf-gae096ac9215c #1 SMP PREEMPT Tue May 24 18:19:47 CST 2022 aarch64 Android
Device manufacturer:
Xiaomi
Device model:
M2007J20CG
LD Variables:
LD_LIBRARY_PATH=
LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so
Installed termux plugins:
com.termux.styling versionCode:30

Edit:
updated the test script so it doesn't require a keypress indefinitely!
it shows the opencv output then waits 500ms for a keypress, then continues to run the matplotlib codes which should display the same image in another window.

Grimler91 commented 7 months ago

Please try upgrading your packages (specifically you have a matplotlib update waiting)

Coderx7 commented 7 months ago

Thanks for the reminder. I did upgrade but the problem remains unaffected.

Biswa96 commented 6 months ago

I can not reproduce the issue with a clean install of termux and those new opencv packages. The python script ran fine and it shows a chess like image as following.

image

By the way, the above screenshot is from Linux desktop ssh into termux with X11 forwarding. termux-x11 does not work properly. Also, I can not stop the python script with Ctrl+C but kill works.

Coderx7 commented 6 months ago

you are only seeing the opencv output, press a key and that window closes, and the matplotlib runs. you can run this script if you don't want to press any keys :

import cv2
import numpy as np
import matplotlib.pyplot as plt

# create a simple image
image = np.kron([[1, 0] * 4, [0, 1] * 4] * 4, np.ones((50, 50))).astype(np.uint8) * 255
# Test opencv 
cv2.imshow('checkboard',image)
# wait for 500 ms or a keypress to continue 
# 0 means wait indefinitely until a key is pressed
cv2.waitKey(500)
# Test matplotlib
plt.imshow(image)
plt.show()

side note: the x11 works properly, it's the opencv behavior when you use cv2.waitKey(0), you have to press a key, closing the window wouldn't end the app cuz it's still waiting for a key!

Biswa96 commented 6 months ago

After pressing Enter key, I got the following warning.

/data/data/com.termux/files/home/./matplotlib-test.py:12: UserWarning: FigureCanvasAgg is non-interactive, and thus cannot be shown
  plt.show()
Coderx7 commented 6 months ago

the warning is OK and expected but do you get an output from matplotlib?!

Biswa96 commented 6 months ago

do you get an output from matplotlib?!

No, I did not get any error from matplotlib. Try with a clean termux install if possible. The python package management in termux is a bit inconvenient.

Coderx7 commented 6 months ago

@Biswa96, by output I meant an image! you should get an output, another window showing the same image, the warning only happens when you run this using a python instance and can be ignored. if yes, then I need to dig deeper and see why Im facing this issue!

Biswa96 commented 6 months ago

Yes, I get two window - one with the above image and another one as following screenshot.

image

Biswa96 commented 6 months ago

Wait a sec, does recompiling packages change the result? I have to create contourpy and kiwisolver packages because my ancient phone can not compile those with lower memory.

Coderx7 commented 6 months ago

yup, that's it, you are getting the expected outputs! I'm not sure about the recompiling though, I dont think recompiling packages on your phone has anything to do with this.

Biswa96 commented 6 months ago

Could you provide the output of pip list ?

Coderx7 commented 6 months ago

here you are

~ $ pip list
Package                   Version
------------------------- ------------
ai-einblick-prompt        0.1.12
aiohttp                   3.8.5
aiohttp-socks             0.8.0
aiorpcX                   0.22.1
aiosignal                 1.3.1
anyio                     3.7.1
argon2-cffi               21.3.0
argon2-cffi-bindings      21.2.0
arrow                     1.2.3
asciinema                 2.4.0
asttokens                 2.2.1
async-lru                 2.0.4
async-timeout             4.0.2
attrs                     23.1.0
Babel                     2.12.1
backcall                  0.2.0
beautifulsoup4            4.12.2
bitstring                 4.0.2
bleach                    6.0.0
certifi                   2023.7.22
cffi                      1.15.1
charset-normalizer        3.2.0
comm                      0.1.4
contourpy                 1.2.1
cryptography              42.0.5
cycler                    0.11.0
debugpy                   1.6.8
decorator                 5.1.1
defusedxml                0.7.1
dnspython                 2.4.1
Electrum                  4.5.4
executing                 1.2.0
fastjsonschema            2.18.0
filelock                  3.12.2
fonttools                 4.42.0
fqdn                      1.5.1
frozenlist                1.4.0
idna                      3.4
ipykernel                 6.25.0
ipython                   8.14.0
ipython-genutils          0.2.0
ipywidgets                8.1.0
isoduration               20.11.0
jedi                      0.19.0
Jinja2                    3.1.2
json5                     0.9.14
jsonpointer               2.4
jsonschema                4.18.6
jsonschema-specifications 2023.7.1
jupyter                   1.0.0
jupyter_client            8.3.0
jupyter-console           6.6.3
jupyter_core              5.3.1
jupyter-events            0.7.0
jupyter-lsp               2.2.0
jupyter_server            2.7.0
jupyter_server_terminals  0.4.4
jupyterlab                4.0.4
jupyterlab-pygments       0.2.2
jupyterlab_server         2.24.0
jupyterlab-widgets        3.0.8
kiwisolver                1.4.4
MarkupSafe                2.1.3
matplotlib                3.8.4
matplotlib-inline         0.1.6
meson                     1.2.0
meson-python              0.13.2
mistune                   3.0.1
mpmath                    1.3.0
multidict                 6.0.4
nbclient                  0.8.0
nbconvert                 7.7.3
nbformat                  5.9.2
nest-asyncio              1.5.7
networkx                  3.1
notebook                  7.0.1
notebook_shim             0.2.3
numpy                     1.26.4
overrides                 7.3.1
packaging                 23.1
pandas                    2.2.2
pandocfilters             1.5.0
parso                     0.8.3
pexpect                   4.8.0
pickleshare               0.7.5
pillow                    10.3.0
pip                       24.0
platformdirs              3.10.0
prometheus-client         0.17.1
prompt-toolkit            3.0.39
protobuf                  3.20.3
psutil                    5.9.5
ptyprocess                0.7.0
pure-eval                 0.2.2
pybind11                  2.11.1
pycparser                 2.21
pyfiglet                  0.8.post1
Pygments                  2.15.1
pyparsing                 3.0.9
pypng                     0.20220715.0
pyproject-metadata        0.7.1
PyQt5                     5.15.10
PyQt5-sip                 12.12.2
python-dateutil           2.8.2
python-json-logger        2.0.7
python-socks              2.3.0
pytz                      2023.3
PyYAML                    6.0.1
pyzmq                     25.1.0
QDarkStyle                3.1
qrcode                    7.4.2
qtconsole                 5.4.3
QtPy                      2.3.1
ranger-fm                 1.9.3
referencing               0.30.0
requests                  2.31.0
rfc3339-validator         0.1.4
rfc3986-validator         0.1.1
rpds-py                   0.9.2
Send2Trash                1.8.2
six                       1.16.0
sniffio                   1.3.0
soupsieve                 2.4.1
stack-data                0.6.2
sympy                     1.12
terminado                 0.17.1
tinycss2                  1.2.1
torch                     2.1.2
torchaudio                2.0.1
torchvision               0.15.1
tornado                   6.3.2
traitlets                 5.9.0
typing_extensions         4.7.1
tzdata                    2023.3
uri-template              1.3.0
urllib3                   2.0.4
wcwidth                   0.2.6
webcolors                 1.13
webencodings              0.5.1
websocket-client          1.6.1
widgetsnbextension        4.0.8
yarl                      1.9.2
~ $
Biswa96 commented 6 months ago

Please update PyQt5-sip package using pip. There should be a version constrain in pyqt5 package. I will add it later.