Repository: spyder-ide/spyder

Issue:
Spyder not launching when Kite installation is faulty
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->

### Issue Report Checklist

* [x] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [x] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [x] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)
* [ ] Could not reproduce inside ``jupyter qtconsole`` (if console-related)
* [x] Tried basic troubleshooting (if a bug/error)
    * [x] Restarted Spyder
    * [x] Reset preferences with ``spyder --reset``
    * [x] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)
    * [ ] Tried the other applicable steps from the Troubleshooting Guide
* [x] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description
Spyder crashing upon startup.

I have just installed anaconda3 on this computer (a first time install), and updated anaconda and spyder to the newest versions. Initially it worked fine, but having forgotten numpy, I closed down, and installed it. When trying to open spyder4 again it would not work. I have restarted my pc, uninstalled and reinstalled anaconda and spyder a few times, and never have I gotten spyder to open again.

### What steps reproduce the problem?

1. Fresh install of conda from website (64-Bit Graphical Installer for python 3.7)
2. In the conda prompt write `conda update anaconda` followed by `conda install spyder=4.0.1`
(Note to 2: When updating anaconda it'll post some debugging lines, and when installing spyder it'll fail with initial frozen solve to solve the environment and commence debugging at the end - see screenshots for all) 
3. Run `spyder --reset`
4. Launch spyder

### What is the expected output? What do you see instead?
Pops up with the traceback instead of opening spyder.


### Paste Traceback/Error Below (if applicable)
<!--- Copy from error dialog or View > Panes > Internal Console --->

```python-traceback

Traceback (most recent call last):
File "F:\Anaconda\lib\site-packages\spyder\app\mainwindow.py", line 3718, in main
mainwindow = run_spyder(app, options, args)
File "F:\Anaconda\lib\site-packages\spyder\app\mainwindow.py", line 3559, in run_spyder
main.setup()
File "F:\Anaconda\lib\site-packages\spyder\app\mainwindow.py", line 960, in setup
self.completions.start()
File "F:\Anaconda\lib\site-packages\spyder\plugins\completion\plugin.py", line 292, in start
client_info['plugin'].start()
File "F:\Anaconda\lib\site-packages\spyder\plugins\completion\kite\plugin.py", line 141, in start
self.kite_process = run_program(path)
File "F:\Anaconda\lib\site-packages\spyder\utils\programs.py", line 214, in run_program
return subprocess.Popen(fullcmd, **subprocess_kwargs)
File "F:\Anaconda\lib\subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "F:\Anaconda\lib\subprocess.py", line 1178, in _execute_child
startupinfo)
OSError: [WinError 193] %1 is not a valid Win32 application


```

## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: 4.0.1
* Python version: 3.7.4 (also tried 3.7.6 with no change)
* Qt version: 5.9.7
* PyQt version: 5.9.2
* Operating System name/version: Windows 10

### Dependencies
<!--- Please go to the menu entry Help > Dependencies,
press the Copy to clipboard button and paste below --->

```
I'm assuming this is if spyder is launchable - which it isn't for me. (cannot find this)
```

### Pictures of prompt window (from note to 2)
![updating conda](https://user-images.githubusercontent.com/61242596/74856295-36c44200-5342-11ea-813c-b04580484926.png)
![installing spyder](https://user-images.githubusercontent.com/61242596/74856293-36c44200-5342-11ea-87f7-d7c863016047.png)
![installing spyder 2](https://user-images.githubusercontent.com/61242596/74856291-362bab80-5342-11ea-8d16-6c8eecb75c9c.png)



Discussion:
If you have Kite installed, please uninstall it. That should solve your problem.

@dalthviz, do you know what's happening in this case?
> If you have Kite installed, please uninstall it. That should solve your problem.

When I first launched spyder (the time it worked) it asked if I wanted to install Kite, which I just accepted. The install failed and installer closed, and I thought nothing more of it. I cannot find kite using Window's add/remove programs feature, so I don't know if there are some files from it remaining from the failed install.

@ccordoba12 ~~I'm not sure but maybe some how the failed installation make available the service that Kite uses while actually not being installed?~~ Probably caused by remaining files of the failed installation that by pass the check of Kite being installed.

@Klumpfisk could you check if there is Kite related processes running in your machine? Also, could you try to download the installer manually (available [here](https://kite.com/download/)) and try to install Kite?. For example, when I run the installer I get the following message:

![image](https://user-images.githubusercontent.com/16781833/74865532-3fefe780-531f-11ea-9db2-41e48053273d.png)

Edit: Reviewing the way we check if Kite is installed, we validate if the path `C:\Program Files\Kite\kited.exe` exists. @Klumpfisk could you try to check if you have a folder `C:\Program Files\Kite` and delete it?


Okay, so it seems kite has made a folder on my machine with that path, however it doesn't have an uninstaller. I get the same message when trying to install kite. I'll try to manually remove the folder and check it (I'll need to install a few things again as I reinstalled conda and used the 3.3.6 version of spyder)
![kite](https://user-images.githubusercontent.com/61242596/74866540-56b03180-5353-11ea-9564-7e20c6f9d4e6.png)

Alright, that fixed it.
Thanks a lot, would've never found this on my own :)
Thanks for the patience to reinstall everything @Klumpfisk ! Glad you could make it work :)
@ccordoba12 maybe we need to add at least a message regarding failed installations and the need of a manual (or automatic) deletion of remaining files?
> maybe we need to add at least a message regarding failed installations and the need of a manual (or automatic) deletion of remaining files?

Definitely, please open a PR for that.

Resolving patch:
diff --git a/spyder/config/main.py b/spyder/config/main.py
--- a/spyder/config/main.py
+++ b/spyder/config/main.py
@@ -519,6 +519,7 @@
               # Enable the installation dialog
               'show_installation_dialog': True,
               'show_onboarding': True,
+              'show_installation_error_message': True,
              }),
             ]
 
diff --git a/spyder/plugins/completion/kite/plugin.py b/spyder/plugins/completion/kite/plugin.py
--- a/spyder/plugins/completion/kite/plugin.py
+++ b/spyder/plugins/completion/kite/plugin.py
@@ -9,9 +9,11 @@
 # Standard library imports
 import logging
 import functools
+import os.path as osp
 
 # Qt imports
 from qtpy.QtCore import Slot
+from qtpy.QtWidgets import QMessageBox
 
 # Local imports
 from spyder.config.base import _, running_under_pytest
@@ -25,6 +27,7 @@
     KiteInstallationThread)
 from spyder.plugins.completion.kite.widgets.install import KiteInstallerDialog
 from spyder.plugins.completion.kite.widgets.status import KiteStatusWidget
+from spyder.widgets.helperwidgets import MessageCheckBox
 
 
 logger = logging.getLogger(__name__)
@@ -139,6 +142,33 @@ def start(self):
                 return
             logger.debug('Starting Kite service...')
             self.kite_process = run_program(path)
+        except OSError:
+            installed, path = check_if_kite_installed()
+            logger.debug(
+                'Error starting Kite service at {path}...'.format(path=path))
+            if self.get_option('show_installation_error_message'):
+                box = MessageCheckBox(
+                    icon=QMessageBox.Critical, parent=self.main)
+                box.setWindowTitle(_("Kite installation error"))
+                box.set_checkbox_text(_("Don't show again."))
+                box.setStandardButtons(QMessageBox.Ok)
+                box.setDefaultButton(QMessageBox.Ok)
+
+                box.set_checked(False)
+                box.set_check_visible(True)
+                box.setText(
+                    _("It seems that your Kite installation is faulty. "
+                      "If you want to use Kite, please remove the "
+                      "directory that appears bellow, "
+                      "and try a reinstallation:<br><br>"
+                      "<code>{kite_dir}</code>".format(
+                          kite_dir=osp.dirname(path))))
+
+                box.exec_()
+
+                # Update checkbox based on user interaction
+                self.set_option(
+                    'show_installation_error_message', not box.is_checked())
         finally:
             # Always start client to support possibly undetected Kite builds
             self.client.start()


Test patch: