Repository: spyder-ide/spyder

Issue:
No xdg-open on VM instance
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

 On a VM instance (e.g. google cloud) without xdg-open, run spyder using ssh -X, then use "Show in external file explorer".

### Traceback
```python-traceback
  File "/usr/local/anaconda3/envs/ludwig/lib/python3.7/site-packages/spyder/plugins/editor/widgets/editor.py", line 621, in show_in_external_file_explorer
    show_in_external_file_explorer(fnames)
  File "/usr/local/anaconda3/envs/ludwig/lib/python3.7/site-packages/spyder/plugins/explorer/widgets/explorer.py", line 70, in show_in_external_file_explorer
    open_file_in_external_explorer(fname)
  File "/usr/local/anaconda3/envs/ludwig/lib/python3.7/site-packages/spyder/plugins/explorer/widgets/explorer.py", line 58, in open_file_in_external_explorer
    subprocess.call(["xdg-open", filename])
  File "/usr/local/anaconda3/envs/ludwig/lib/python3.7/subprocess.py", line 339, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/local/anaconda3/envs/ludwig/lib/python3.7/subprocess.py", line 800, in __init__
    restore_signals, start_new_session)
  File "/usr/local/anaconda3/envs/ludwig/lib/python3.7/subprocess.py", line 1551, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'xdg-open': 'xdg-open'
```

## Versions

* Spyder version: 4.1.3 
* Python version: 3.7.7
* Qt version: 5.9.6
* PyQt5 version: 5.9.2
* Operating System: Linux 5.3.0-1032-gcp

### Dependencies

```

# Mandatory:
atomicwrites >=1.2.0           :  1.3.0 (OK)
chardet >=2.0.0                :  3.0.4 (OK)
cloudpickle >=0.5.0            :  1.3.0 (OK)
diff_match_patch >=20181111    :  20181111 (OK)
intervaltree                   :  None (OK)
IPython >=4.0                  :  7.10.1 (OK)
jedi =0.15.2                   :  0.15.2 (OK)
keyring                        :  None (OK)
nbconvert >=4.0                :  5.6.1 (OK)
numpydoc >=0.6.0               :  0.9.2 (OK)
parso =0.5.2                   :  0.5.2 (OK)
pexpect >=4.4.0                :  4.8.0 (OK)
pickleshare >=0.4              :  0.7.5 (OK)
psutil >=5.3                   :  5.7.0 (OK)
pygments >=2.0                 :  2.6.1 (OK)
pylint >=0.25                  :  2.4.4 (OK)
pyls >=0.31.9;<0.32.0          :  0.31.9 (OK)
qdarkstyle >=2.8               :  2.8 (OK)
qtawesome >=0.5.7              :  0.7.0 (OK)
qtconsole >=4.6.0              :  4.7.2 (OK)
qtpy >=1.5.0                   :  1.9.0 (OK)
rtree >=0.8.3                  :  0.9.3 (OK)
sphinx >=0.6.6                 :  2.4.4 (OK)
spyder_kernels >=1.9.1;<1.10.0 :  1.9.1 (OK)
watchdog                       :  None (OK)
xdg >=0.26                     :  0.26 (OK)
zmq >=17                       :  18.1.1 (OK)

# Optional:
cython >=0.21                  :  None (OK)
matplotlib >=2.0.0             :  3.1.2 (OK)
numpy >=1.7                    :  1.17.3 (OK)
pandas >=0.13.1                :  0.25.3 (OK)
scipy >=0.17.0                 :  1.3.2 (OK)
sympy >=0.7.3                  :  None (OK)
```



Discussion:
Hi @SimonDeRidder,
We will work in fixing this error in our next release of Spyder! Thanks for reporting :)
@juanis2112 can you please take a look at this one?

The idea is to catch the error with a try/except and detect if `xdg-open` is present in the error message and create a dialog to inform the user that the functionality depends on that executable which is present in Ubuntu or Debian
Will do!
> on that executable which is present in Ubuntu or Debian

To clarify what @steff456 meant here: the `xdg-open` executable is part of the `xdg-utils` package on those Linux distros.

Resolving patch:
diff --git a/spyder/plugins/editor/widgets/editor.py b/spyder/plugins/editor/widgets/editor.py
--- a/spyder/plugins/editor/widgets/editor.py
+++ b/spyder/plugins/editor/widgets/editor.py
@@ -622,7 +622,17 @@ def show_in_external_file_explorer(self, fnames=None):
         """Show file in external file explorer"""
         if fnames is None:
             fnames = self.get_current_filename()
-        show_in_external_file_explorer(fnames)
+        try:
+            show_in_external_file_explorer(fnames)
+        except FileNotFoundError as error:
+            file = str(error).split("'")[1]
+            if "xdg-open" in file:
+                msg_title = _("Warning")
+                msg = _("Spyder can't show this file in the external file "
+                        "explorer because the <tt>xdg-utils</tt> package is "
+                        "not available on your system.")
+                QMessageBox.information(self, msg_title, msg,
+                                        QMessageBox.Ok)
 
     def create_shortcuts(self):
         """Create local shortcuts"""


Test patch: