Repository: spyder-ide/spyder

Issue:
AttributeError: 'NoneType' object has no attribute 'execute'
## Description

**What steps will reproduce the problem?**

1. 
2. 
3. 

**What is the expected output? What do you see instead?**


**Please provide any additional information below**

  File "C:\Users\cem\Desktop\WinPython-64bit-3.6.2.0Qt5\python-3.6.2.amd64\lib\site-packages\spyder\plugins\ipythonconsole.py", line 876, in run_script
    self.execute_code(line, current_client, clear_variables)
  File "C:\Users\cem\Desktop\WinPython-64bit-3.6.2.0Qt5\python-3.6.2.amd64\lib\site-packages\spyder\plugins\ipythonconsole.py", line 922, in execute_code
    sw.execute(to_text_string(to_text_string(lines)))
  File "C:\Users\cem\Desktop\WinPython-64bit-3.6.2.0Qt5\python-3.6.2.amd64\lib\site-packages\qtconsole\history_console_widget.py", line 47, in execute
    source, hidden, interactive)
  File "C:\Users\cem\Desktop\WinPython-64bit-3.6.2.0Qt5\python-3.6.2.amd64\lib\site-packages\qtconsole\console_widget.py", line 631, in execute
    self._execute(source, hidden)
  File "C:\Users\cem\Desktop\WinPython-64bit-3.6.2.0Qt5\python-3.6.2.amd64\lib\site-packages\qtconsole\frontend_widget.py", line 294, in _execute
    msg_id = self.kernel_client.execute(source, hidden)
AttributeError: 'NoneType' object has no attribute 'execute'


## Version and main components

* Spyder Version: 3.2.1.dev0 
* Python Version: 3.6.2
* Qt Versions: 5.9.1, PyQt5 5.9 on Windows

## Dependencies
```
pyflakes >=0.6.0 :  1.6.0 (OK)
pycodestyle >=2.3:  2.3.1 (O


Discussion:
Please post a screenshot of the IPython console when this error pops up.
@stonebig, are you able to reproduce this one? It looks like a Qt issue to me.
I referred to this error in another issue (#5154). Then I discovered that the error, in my case, was occurring because I had set up another python interpreter, different from the default, and it did'nt have the ipython package.
@marcelotduarte, thanks for letting us know about it! Finally we have an explanation for this!

We'll take a look at it in 3.2.4
@marcelotduarte, I can't reproduce this. Please post the exact steps you followed to set up your another python interpreter.
Configure:
![image](https://user-images.githubusercontent.com/12752334/30470856-cb92151a-99cc-11e7-9d93-61735a587ab7.png)
Close the sypder
Reopen
![image](https://user-images.githubusercontent.com/12752334/30470878-e0ae8960-99cc-11e7-9bc9-ba62fe6c5bd2.png)


Resolving patch:
diff --git a/spyder/plugins/ipythonconsole.py b/spyder/plugins/ipythonconsole.py
--- a/spyder/plugins/ipythonconsole.py
+++ b/spyder/plugins/ipythonconsole.py
@@ -887,7 +887,10 @@ def run_script(self, filename, wdir, args, debug, post_mortem,
                 line += "\"%s\"" % to_text_string(filename)
                 if args:
                     line += " %s" % norm(args)
-            self.execute_code(line, current_client, clear_variables)
+            try:
+                self.execute_code(line, current_client, clear_variables)
+            except AttributeError:
+                pass
             self.visibility_changed(True)
             self.raise_()
         else:
@@ -933,7 +936,7 @@ def execute_code(self, lines, current_client=True, clear_variables=False):
                     sw.reset_namespace(warning=False, silent=True)
                 elif current_client and clear_variables:
                     sw.reset_namespace(warning=False, silent=True)
-                sw.execute(to_text_string(to_text_string(lines)))
+                sw.execute(to_text_string(lines))
             self.activateWindow()
             self.get_current_client().get_control().setFocus()
 
diff --git a/spyder/widgets/ipythonconsole/shell.py b/spyder/widgets/ipythonconsole/shell.py
--- a/spyder/widgets/ipythonconsole/shell.py
+++ b/spyder/widgets/ipythonconsole/shell.py
@@ -290,7 +290,10 @@ def create_shortcuts(self):
     # --- To communicate with the kernel
     def silent_execute(self, code):
         """Execute code in the kernel without increasing the prompt"""
-        self.kernel_client.execute(to_text_string(code), silent=True)
+        try:
+            self.kernel_client.execute(to_text_string(code), silent=True)
+        except AttributeError:
+            pass
 
     def silent_exec_method(self, code):
         """Silently execute a kernel method and save its reply


Test patch: