10

I have freshly installed Ubuntu 18.04 and Anaconda (with Python 3.7) in my laptop, and I want to set up a launcher icon for the Spyder IDE in the Favourites bar - something I've done many times in the past couple of years when running Ubuntu 16.

I can successfully launch Spyder from the Terminal and it seems to be working fine, but when I run it from the terminal and right-click the icon, it does not give me an option for adding it to Favorites.

[Strangely, searching for an application named "spyder" returns no results; not sure if this might be related, but...]

I understand I can manually add an icon for it by creating a .desktop file, as described here and here, and adding it to /usr/share/applications, as described here. For example, I have tried using the following spyder.desktop file (available in the Spyder Github):

[Desktop Entry]
Type=Application
Version=1.0
Name=Spyder
GenericName=Spyder
Comment=The Scientific Python Development Environment
Icon=spyder
TryExec=spyder
Exec=spyder %F
Terminal=false
MimeType=text/x-python;
Categories=Development;Science;IDE;Qt;
Keywords=Development;Science;IDE;Qt;
StartupNotify=true
X-AppStream-Ignore=True
StartupWMClass=Spyder

However, even after creating this file, Spyder still does not show up in Applications. And if I try to run this file, I get a fairly generic

"There was an error launching the application"

message.

Is this a known issue with Spyder and/or Ubuntu 18? Am I missing something here? Any help would be much appreciated! Many thanks!

fabio_hirono
  • 203
  • 1
  • 2
  • 6
  • Just to make sure, at which directory did you put the .desktop file? – pomsky Dec 18 '18 at 22:18
  • I added it to /usr/share/applications - was that the right place? – fabio_hirono Dec 19 '18 at 15:53
  • 1
    Please type this command in the terminal: whereis spyder and post the output – koni_raid Dec 19 '18 at 16:12
  • 1
    @koni_raid The output is spyder: /home/hirono/anaconda3/bin/spyder – fabio_hirono Dec 19 '18 at 16:39
  • @Kulfy The .desktop file has executable permissions. However, I don't understand where I have to add the absolute path in the .desktop file; could you please help me with that? – fabio_hirono Dec 19 '18 at 16:52
  • @fabio_hirono What Kulfy meant is change the Exec=spyder %F line to Exec=/home/hirono/anaconda3/bin/spyder %F. Do the same with TryExec line too. – pomsky Dec 19 '18 at 16:59
  • @pomsky Thanks for the explanation. Funny thing: if I add the absolute path to either Exec or TryExec (but not both), I still get the error message. By adding it to both, I can then run the .desktop file successfully and get Spyder to open. I can now find Spyder in Applications and open it from there, but it doesn't display an icon on the Favourites bar while running! – fabio_hirono Dec 19 '18 at 17:05

2 Answers2

8

As the error message "There was an error launching the application" suggests, there is some sort of error in spyder.desktop. Fields like Exec and TryExec require the absolute path of the executable file, therefore the values for Exec and TryExec must be /home/hirono/anaconda3/bin/spyder. Same goes for Icon. It seems like you haven't given even the extension for the icon image. Value must be like /home/hirono/path-to-icon/icon.png.

Also, double check the permissions of spyder.desktop and /home/hirono/anaconda3/bin/spyder. They both must be executable.

Kulfy
  • 17,696
  • 1
    Awesome! Adding the absolute paths and ensuring the permissions sorted the problem with the .desktop file, and adding a path to the icon (I used /home/hirono/anaconda3/share/icons/spyder3.png ) gave me a nice icon to add and display in my Favourites :) many thanks to all that helped! – fabio_hirono Dec 19 '18 at 17:27
1

The suggestion by Kulfy worked for me. Just as a note for others who are having this issue, I was skeptical that adding the absolute path was the fix I needed since calling spyder from the terminal worked fine and calling

spyder.desktop->

[Desktop Entry]
Type=Application
Version=1.0
Name=Spyder
GenericName=Spyder
Comment=The Scientific Python Development Environment
Icon=spyder
TryExec=spyder
Exec=spyder %F
Terminal=false
MimeType=text/x-python;
Categories=Development;Science;IDE;Qt;
Keywords=Development;Science;IDE;Qt;
StartupNotify=true
X-AppStream-Ignore=True
StartupWMClass=Spyder

as

gtk-launch spyder.desktop

would also launch spyder correctly. I don't know why it matters, but definitely use the abs path for applications not installed via terminal apt-get that have this issue.

after making changes to the <application>.desktop file alt-F2->r->enter to reload profile instead of logging out/ back in.