Executing a python script through .sh or .desktop file not working

713 Views Asked by At

I am setting up a PC running Ubuntu 20.04.3 with a touchscreen and no keyboard/mouse. Due to this, I am putting desktop icons that will run the software needed for data taking/analysis. I was able to set one up with no problem first using a .sh file that executes with a single click, then by using a .desktop file.

The problem I am having is that this will not work with a python3 file that runs tkinter and ROOT. I started off by writing the shebang #!/usr/bin/env python3 at the beginning of the .py file and the .sh file that executes the python file. When I click on the .sh file, nothing happens. If I run the .sh file on the terminal by typing ./Bash_File.sh, it executes with no issues. Also, I did make the .py executable, so I can also run it by going to the directory and typing ./Python_File.py.

I then decided to try with a .desktop file, similar to the first program I got to work. I tried executing both, the .sh file and the .py file, from the .desktop file and I get the same error: ModuleNotFoundError: No Module named 'ROOT'. In the .desktop file, I execute the .py file using Exec=/filepath/Python_File.py. Again, I am able to run this file through the terminal, but not having any luck using the icons to run it. I've looked everywhere online for an answer, but no luck. Thanks for the help

1

There are 1 best solutions below

0
On

Disclaimer: Generic answer as I know nothing about the ROOT module.

This is a python error, it can't find the ROOT module, mostly like a specific file named ROOT.py. The cause is that a Bash login session is different than a Bash system session.

Run this script from a desktop launcher and in the shell:

#!/usr/bin/env bash
echo $PATH | tr : \\n >my_path-`date +%s`

If the two output files are different, figure out which directory contains 'ROOT.py' and add this to your launcher script:

#!/usr/bin/env python3
import sys
sys.path.append('/the/missing/directory')

If this doesn't set you up right away, there are many articles on managing the Linux system path, the difference between a regular Bash shell and a Bash login shell, and how to manage your Python path. HTH