HomeAboutMailing ListList Chatter /0/0

Python script won't work from menu

2022-06-03 by: "Robert A. Kelly III"
From: "Robert A. Kelly III" 

I have a little Python script one of the kids has been working on that 
implements a little game with pygame. It runs fine when invoked from a terminal 
app like Konsole and I thought all he needed to run it from the menu was a 
.desktop file for the menu entry. However, the menu entry thus created does not 
work, nor does invoking the script from Krunner via Alt+F2. Any idea what I 
might be missing to get this to work?

=============================================================== From: John D ------------------------------------------------------ Is your exec line calling Python, like python='python path/to/script' (Some distros will require you to specify Python3 if you don't have python3-is-python installed)? If it's running in a terminal, make sure to set Terminal=True too Admittedly, I haven't tried to create a .desktop file, but I imagine if those params are set it should work.

=============================================================== From: "Robert A. Kelly III" ------------------------------------------------------ I only put the path to the script in the exec line, although it looks like that is how the deluge.desktop file that was installed by the Debian package is written. The script has a #! line pointing to the python3 interpreter, as does the deluge-gtk file that was installed via apt. It is not intended to run in a terminal but rather draws a window for game play. However, when Terminal=true, it briefly opens a terminal window and when false it does not, but in neither case does it draw the game window. It only draws the game window when it is invoked from the terminal app directly.

=============================================================== From: Dave Brockman ------------------------------------------------------ Sounds suspiciously like a missing environmental variable.... Cheers, -dtb

=============================================================== From: John D ------------------------------------------------------ I tested it and it works OK for me, but I just did a simple script. chmod u+x my ..desktop entry on the desktop and it works fine. To me it sounds like the Python script is exiting for some reason. Both are set to have 0740 as the permissions. Here's my script + .desktop entry: (I used python bc Arch allows python3 to be referenced that way, but some distros require it to be python3) ``` #!/usr/bin/env python import time print("hello world") time.sleep(100) ``` Desktop File: ``` [Desktop Entry] Name=Test Version=0.01 Exec=/home/john/test.py Terminal=True Type=Application ```

=============================================================== From: Unkmar ------------------------------------------------------ Could be useful, if you can redirect standard error (stderr) to a file. Try? Exec=/home/john/test.py 2> /home/john/test_error.txt

=============================================================== From: Deidre Holtsclaw ------------------------------------------------------ I would add a try / except in __main__ printing to a file. My guess is you're missing a dependency and don't have the environment to get it loaded when running from the .desktop. I'm assuming you don't have a setup.py installing it =E2=80=A6 There are many things that can go wrong there. But almost all, basically, boil down to that: A missing dependency : s o n n e