Score:0

Run Python script from Desktop icon, ModuleNotFoundError

nz flag

My Plan is to run a Python script which is a GUI trough clicking on an desktop icon. Im working on a Raspberry Pi 4B with Ubuntu 22.04. It works well with a basic GUI without further functionalities (tutorial: https://linuxhint.com/run-python-script-desktop-icon-linux/ ) . If im trying to import something like opencv in the script, i get a „ModulNotFoundError“. The script works fine in my normal enviroment where i have installed these libraries. So my question is: Where do i have to install these libraries like opencv if the script runs from the desktop icon ?

ru flag
What is the desktop icon configured to run? If it's not calling the Python version within your venv that uses `opencv` then you have to specify the full executable path BEFORE your script that will allow it to execute. If the file is being directly executed, then you need to use `#!/path/to/venv/bin/python3` in the first line of your script to tell it to use your venv Python3 and not system default python
lennart avatar
nz flag
thank you very much, it worked :)
ru flag
Good to hear, I've written this as an answer, so please mark it as accepted! :)
Score:0
ru flag

When you are using a venv for things, which it seems you are, you need to use a different configuration mechanism for the script.

At the beginning of your script, you need to use something like this:

#!/path/to/venv/bin/python3

... and use the full path to your venv. That will then make the script use your venv which has opencv configured in it, rather than the system-wide Python installation and libraries.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.