4

I have a basic .desktop file for a .py:

[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=Appy
Comment=some app
Exec=/home/me/Documents/py/cs/simi0op.py
Icon=/usr/share/icons/hicolor/48x48/apps/pic.jpeg
Terminal=true

When I double click the desktop icon I get a terminal err msg that the .ext isn't in path. But it is.

My err msg :

Failed to execute child process “path/to/file.py” (No such file or directory)

But I can cd via terminal and run via python3 without problem. The .py file does use an import or two but these work fine so they should work from the .desktop shortcut as well...no?

My Exec var is correctly set up, I think. Clicking on icon produces error, but file exists - and runs via python3 in terminal:

chmod problems

meyeti
  • 59
  • 1
  • 5
  • Is the file executable? – muru Jan 25 '18 at 00:23
  • I'm a little new at this...but i believe it is. .desktop ext is the linux version of .exe – meyeti Jan 25 '18 at 00:32
  • That is not how executables work in Linux. The permissions on the file matter: https://askubuntu.com/a/156397/158442 – muru Jan 25 '18 at 00:35
  • you could also try putting the full cmd line in Exec= Exec=/usr/bin/python3 /home/[username]/path/file.py – John Orion Jan 25 '18 at 00:46
  • 1
    What's the first line of the py file? – muru Jan 25 '18 at 01:34
  • @muru I tried file filename.desktop and the file type is ASCII so I guess it is not executable? How do I make it so if it isn't yet...the question u pointed to doesn't actually provide an answer... – meyeti Jan 25 '18 at 22:05
  • @meyeti I don't know why you tried that or what bearing that has on anything I asked. The post I linked to clearly says "Even text files (like shell scripts) can have their executable bits set, and be run as one." and " To see if a file is executable, you can check its properties (Permissions tab)". If you insist on ignoring what I say, then I can't help you. – muru Jan 26 '18 at 00:56
  • You can also make it executable from the command line: chmod a+x /home/me/Documents/py/cs/simi0op.py. Make sure the python script has a shebang. – frabjous Mar 21 '22 at 16:44
  • 5

3 Answers3

4

Have you tried:

[Desktop Entry]
Version=1.0
Type=Application
Name=Appy
Comment=
Exec=/home/[username]/path/file.py
Icon=/usr/share/icons/hicolor/48x48/apps/pic.jpeg
Path=/home/[username]/path
Terminal=false
StartupNotify=false

Maybe try terminal=false .. I have a script that runs using this setup with terminal false and you may want to add the path line

John Orion
  • 2,801
1

The culprit for me was substituting my home directory absolute path i.e. /home/[username]/ with the shell reserved character tilde ~ that normally designates the home directory when working at the shell itself. If that's case, then revert back to the clear-cut path.

xquilt
  • 117
  • Thank you so much for this. I spent 4 hours trying to figure out why I couldn't login to my desktop environment. After attempting may things (which I'm sure modified my system in a number of undesirable ways). This was the issue at the end of the day. – George S Mar 08 '23 at 16:45
  • 1
    @GeorgeS Glad it helped. – xquilt Mar 09 '23 at 09:13
1

Most likely you need to execute chmod +x /home/[username]/path/file.py, replacing [username] with your actual user name.

If that fails please copy/paste the exact contents of your .desktop file and the exact error message. Changing stuff to "path/to/file.py" can hide useful information and make it harder for us to help you.

sмurf
  • 4,680
  • chmod failed +x failed... – meyeti Jan 25 '18 at 00:23
  • you need to use sudo before the command sudo chmod +x /home/[username]/path/file.py – John Orion Jan 25 '18 at 00:32
  • 2
    @JohnOrion no, you don't need to if you have permissions on the directory. – muru Jan 25 '18 at 00:33
  • @muru I'm assuming that he doesn't since it failed ... why else would it fail? but this doesn't seem to be his problem . .he said he can run it if he goes to the directory and runs it in terminal so .. its executable already – John Orion Jan 25 '18 at 00:38
  • @JohnOrion the screenshot shows he runs it using python file.py, which says nothing about whether the file is executable, and he doesn't give the actual error either: "chmod failed +x failed" is somewhat meaningless. – muru Jan 25 '18 at 00:45
  • @meyeti what was the actual error you got? – muru Jan 25 '18 at 00:45
  • @muru sorry .. I thought even if you used python3 and then the script .. the script still needed to be marked executable for it to work ... I still get permissions confused lol .. wouldn't he need to use ./home/[username]/path/file.pyor python3 /home/[username]/path/file.py as the exec line then? lol never got what the ./scriptname and scriptname differ but I know sometimes you have to use the ./ and sometimes you don't – John Orion Jan 25 '18 at 00:49
  • @John Orion ./ has given me problems in the past. – meyeti Jan 25 '18 at 01:23
  • @muru the actual err as seen in image is 'failure to execute child process (file doesn't exit). It clearly does exist – meyeti Jan 25 '18 at 01:24
  • I meant the error you got for chmod @meyeti – muru Jan 25 '18 at 01:25
  • @muru added image for chmod... – meyeti Jan 25 '18 at 01:33