1

I have a .py script that I want to have the option to open with Spyder when I right-click on the file icon. If I right click on the script and select the "open with another application" command I get a list of programs installed on my computer that I can use to open the file with, however, Spyder is not one of the selected lists.

enter image description here

Spyder appears under my Applications>engineerng tab from the main drop-down menu. in my /usr/share/applications folder, I have the following Spyder.desktop file

[Desktop Entry]
Type=Application
Exec=spyder
Name=spyder
GenericName=Scientific Python Development Environment
Comment=A simple and lightweighted python IDE with MATLAB-like features
Icon=/home/adowney2/anaconda3/lib/python3.6/site-packages/anaconda_navigator/static/images/spyder-icon-1024x1024.png
Terminal=false
Categories=Development;IDE;Engineering;Mathematics;
1

Default file associations are stored in /usr/share/applications/mimeapps.list. User customizations can be added to ~/.config/mimeapps.list. Note that per-user settings (in ~/.config/mimeapps.list) trump system-wide settings. In this case, you would add a line like this:

text/x-python=spyder.desktop

This makes Spyder the default application for opening Python files. You can also add other apps to make them available through the Open With Other Application menu item, such as:

text/x-python=spyder.desktop;org.gnome.gedit.desktop;

RHEL7 GNOME Context Menu with Python

The above assumes that the spyder.desktop file was added to your system when you installed Spyder. I installed from the EPEL repository, which supplies this file in /usr/share/applications/spyder.desktop. If you installed from a different source that doesn't provide the file, add it as ~/.local/share/applications/spyder.desktop:

[Desktop Entry]
Type=Application
Exec=spyder
Name=Spyder
GenericName=Scientific Python Development Environment
Comment=A simple and lightweighted python IDE with MATLAB-like features
Icon=spyder
Terminal=false
Categories=Development;IDE;

See the documentation for Overriding the Default Registered Application for Individual Users in the RHEL Desktop Migration and Administration Guide.

  • Thanks, however, I am still not able to get this to work. I added the line text/x-python=spyder.desktop;org.gnome.gedit.desktop; to my '/usr/share/applications/mimeapps.list' file. I have the spyder.desktop file that I added to the question description. I looked at the link you provided but it seems that I have to add a .xml file to `/usr/share/mime/packages/application-x-newtype.xml' for the .py file extensions. This seems more complicated than it should be. – Austin Downey Oct 22 '17 at 6:45
  • @Austin, you shouldn't need to add the MIME definition (the XML) file because it already exists in the default installation (/usr/share/mime/text/x-python.xml, which is installed by the shared-mime-info package). Check if this file exists. If it does, check the spyder.desktop file for correctness. I just tried the described steps, and it worked as expected. – Robert Kratky Oct 22 '17 at 7:02
  • Sorry, still not working. I did check and I do have the file usr/share/mime/text/x-python.xml, and my file names are correct. From the terminal, if I use ls to list the files in /usr/share/applications/ I see spyder.desktop. I updated my file to match yours, see the updated question and I have restarted my computer a few times. I am working completely out of the /usr/share/applications/ locations, I am not sure what the config/mimeapps.list is referring to. Should I be updating this? – Austin Downey Oct 22 '17 at 7:45
  • Ok, I now see that .config/mimeapps.list' is under home/usr. If I open this file I have a only one line under default applications that reads text/x-python=org.gnome.gedit.desktop;, I changed this to [Default Applications] text/x-python=spyder.desktop;org.gnome.gedit.desktop;` and everything works fine. If you could point this out in your answer that would be amazing! The main issue is that there are many mimeapps.list in the system and I just needed to update the correct one. – Austin Downey Oct 22 '17 at 7:54
  • OK, I added a note saying the per-user settings take preference over system-wide settings. Glad you were able to get it working. – Robert Kratky Oct 23 '17 at 9:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.