Friday, November 12, 2021

[SOLVED] Python3 GUI script does not work when double clicked

Issue

My GUI script that is a PyQt5 file (.pyw extension) does work when running on my IDE with a build configuration that tells the compiler to run the script with python3:

enter image description here

And it also works when i tell to the regular terminal on Linux to run same script with python3 like this:

enter image description here

When runned with the default python (python2.7) on a regular terminal it tells: ImportError: No module named PyQt5.QtWidgets.

My code does it have these lines on the start to tell that is a python3 script like: #!/usr/bin/python3 or #!/usr/bin/env python3 (I have python3 installed).

When double clicked on the Linux Mint File Explorer the cursor turns crosshair and nothing happends, with the terminal option, same happends and a empty terminal shows. Im talking these options

enter image description here

I guess Linux Mint still runs the scripts with python2.7 even when I added the bash lines to tell

Someone knows why the lines:

  • #!/usr/bin/python3
  • #!/usr/bin/env python3

doesnt work when just double click?

I want to run the script from the Linux File Explorer without the need of an IDE or using the terminal.


Solution

Try chmod +x file.py and run it in terminal by using ./file.py also try lunching the file from a different path, like python3 ~/path/to/file.py and see if the error persists



Answered By - Pierre