Hi Aivar, thank you for the fast answer!
The -i did not solve the problem.
Seemingly,
in my case
Thonny uses a better Python interpreter than python3.
To calculate and display a color pixel graphic (ppm PhotoImage) I need cv2 and numpy.
My program test_GUI.py runs under thonny but not under seemingly equal python3.
Do you happen to have any idea to solve my problem, please?
Thank you,
thonny_starter
-------------------------------
# This is my program test_GUI.py
# I have left out all my needed cv2 and numpy code lines because the problem exists even without these!
from tkinter import *
import numpy as np
import cv2
win = Tk()
win.mainloop()
-------------------------------
On two identical
Raspberry Pi 4 Model B Rev 1.4
with
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 10 (buster)
Release: 10
Codename: buster
and Kernel
5.10.63-v7l+
I get the following:
test_GUI.py runs under thonny!
But with the raspi shell command
sudo python3 test_GUI.py
I get this python3 error message:
RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd
Traceback (most recent call last):
File "test_GUI.py" , line 3, in <module>
import cv2
File "/usr/local/lib/python3.7/dist-packages/cv2/__init__.py", line 5, in <module>
from .cv2 import *
ImportError: numpy.core.multiarray failed to import
This is strange, because thonny and python3 seem to be configured exactly the same (Python 3.7.3, Tk 8.6.9, numpy 1.21.5), which I have verified.
I had to undergo all the following steps in order to successfully import cv2 in Thonny (but unfortunately not yet in python3):
pip3 install --upgrade numpy
# (installs numpy-1.21.5)
sudo apt-get install python3-tk
# (installs tkinter 3.7.3-1)
sudo pip3 install opencv-contrib-python==4.5.3.56
# (because "sudo pip3 install opencv-contrib-python==4.5.4.60" and the standard "sudo pip3 install opencv-contrib-python" hung up)
sudo apt-get install libhdf5-dev libhdf5-serial-dev libhdf5-103
sudo apt-get install libqtgui4 libqtwebkit4 libqt4-test
sudo apt-get install libatlas-base-dev
sudo apt-get install libjasper-dev
wget
https://bootstrap.pypa.io/get-pip.py sudo python3 get-pip.py