Repository: spyder-ide/spyder

Issue:
PermissionError when launching kernel
 
<!--- **PLEASE READ:** Before submitting here, please carefully consult our *Troubleshooting Guide*: https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ and search the issues page for your error/problem, as most posted bugs are duplicates or easy fixes.

If you don't find anything, please provide a detailed step-by-step description (in English) of the problem and what led up to it below. Issue reports without a clear way to reproduce them will be closed. Thanks! --->

## Problem Description

### What steps will reproduce the problem?

I just launched Spyder, then the problem appears. I tried to restart Spyder, but it does not solve the problem.

### Traceback
```python-traceback
  File "C:\Users\Ziru\Anaconda3\envs\tf_gpu\lib\site-packages\spyder\plugins\__init__.py", line 514, in <lambda>
    toggled=lambda checked: self.toggle_view(checked),
  File "C:\Users\Ziru\Anaconda3\envs\tf_gpu\lib\site-packages\spyder\plugins\ipythonconsole.py", line 725, in toggle_view
    self.create_new_client(give_focus=False)
  File "C:\Users\Ziru\Anaconda3\envs\tf_gpu\lib\site-packages\spyder\plugins\ipythonconsole.py", line 1046, in create_new_client
    self.connect_client_to_kernel(client, is_cython=is_cython)
  File "C:\Users\Ziru\Anaconda3\envs\tf_gpu\lib\site-packages\spyder\plugins\ipythonconsole.py", line 1074, in connect_client_to_kernel
    is_cython=is_cython)
  File "C:\Users\Ziru\Anaconda3\envs\tf_gpu\lib\site-packages\spyder\plugins\ipythonconsole.py", line 1522, in create_kernel_manager_and_kernel_client
    kernel_manager.start_kernel(stderr=stderr)
  File "C:\Users\Ziru\Anaconda3\envs\tf_gpu\lib\site-packages\jupyter_client\manager.py", line 259, in start_kernel
    **kw)
  File "C:\Users\Ziru\Anaconda3\envs\tf_gpu\lib\site-packages\jupyter_client\manager.py", line 204, in _launch_kernel
    return launch_kernel(kernel_cmd, **kw)
  File "C:\Users\Ziru\Anaconda3\envs\tf_gpu\lib\site-packages\jupyter_client\launcher.py", line 128, in launch_kernel
    proc = Popen(cmd, **kwargs)
  File "C:\Users\Ziru\Anaconda3\envs\tf_gpu\lib\subprocess.py", line 676, in __init__
    restore_signals, start_new_session)
  File "C:\Users\Ziru\Anaconda3\envs\tf_gpu\lib\subprocess.py", line 957, in _execute_child
    startupinfo)
PermissionError: [WinError 5] Access is denied
```

## Package Versions

* Spyder version: 3.2.8 
* Python version: 3.5.5
* Qt version: 5.6.2
* PyQt5 version: 5.6
* Operating system: Windows 10

### Dependencies

```
pyflakes >=0.6.0 :  2.0.0 (OK)
pycodestyle >=2.3:  2.4.0 (OK)
pygments >=2.0   :  2.2.0 (OK)
pandas >=0.13.1  :  0.23.1 (OK)
numpy >=1.7      :  1.14.5 (OK)
sphinx >=0.6.6   :  1.7.5 (OK)
rope >=0.9.4     :  0.10.7 (OK)
jedi >=0.9.0     :  0.12.0 (OK)
nbconvert >=4.0  :  5.3.1 (OK)
sympy >=0.7.3    :  None (NOK)
cython >=0.21    :  None (NOK)
qtconsole >=4.2.0:  4.3.1 (OK)
IPython >=4.0    :  6.4.0 (OK)
pylint >=0.25    :  1.9.2 (OK)
```




Discussion:
Thanks for reporting. We'll take a look at this in a future release.

Resolving patch:
diff --git a/spyder/plugins/ipythonconsole.py b/spyder/plugins/ipythonconsole.py
--- a/spyder/plugins/ipythonconsole.py
+++ b/spyder/plugins/ipythonconsole.py
@@ -1556,7 +1556,15 @@ def create_kernel_manager_and_kernel_client(self, connection_file,
                 stderr = None
         else:
             stderr = None
-        kernel_manager.start_kernel(stderr=stderr)
+
+        # Catch any error generated when trying to start the kernel
+        # See issue 7302
+        try:
+            kernel_manager.start_kernel(stderr=stderr)
+        except Exception:
+            error_msg = _("The error is:<br><br>"
+                          "<tt>{}</tt>").format(traceback.format_exc())
+            return (error_msg, None)
 
         # Kernel client
         kernel_client = kernel_manager.client()


Test patch: