Repository: spyder-ide/spyder

Issue:
SPYDER_DEBUG=3 is failing on Windows
## Description of your problem

**What steps will reproduce the problem?**

1. Updated to 3.2 through "conda update --all"
2. Open Spyder and try to run any script through F5
3. Executed spyder --reset and spyder --default
4. Also tried "conda uninstall spyder" and then "conda install spyder"
5. Also restarted PC

**What is the expected output? What do you see instead?**
I expect the script to run, instead I get "NameError: name 'runfile' is not defined"

**Please provide any additional information below**
"C:\...>set SPYDER_DEBUG=3
C:\...>spyder --show-console

Traceback (most recent call last):
  File "C:\Users\gabriel\Anaconda3\Scripts\spyder-script.py", line 5, in <module>
    sys.exit(spyder.app.start.main())
  File "C:\Users\gabriel\Anaconda3\lib\site-packages\spyder\app\start.py", line 136, in main
    mainwindow.main()
  File "C:\Users\gabriel\Anaconda3\lib\site-packages\spyder\app\mainwindow.py", line 3025, in main
    or options.optimize)
  File "C:\Users\gabriel\Anaconda3\lib\site-packages\spyder\utils\windows.py", line 33, in set_attached_console_visible
    return bool(ShowWindow(console_window_handle, flag[state]))
KeyError: 3"

Not sure if related but I also get this when updating/installing/uninstalling Spyder through conda
" INFO menuinst_win32:__init__(182): Menu: name: 'Anaconda${PY_VER} ${PLATFORM}', prefix: 'C:\Users\xyz\Anaconda3', env_name: 'None', mode: 'None', used_mode: 'user' "

## Versions and main components

* Spyder Version: 3.2.0
* Python Version: 3.6.2
* Qt Version: 5.6.2
* PyQt Version: 5.6.0
* Operating system: Windows 10 64 bits

## Dependencies

Please go to the menu entry `Help > Optional Dependencies` (or
`Help > Dependencies`), press the button `Copy to clipboard`
and paste the contents below:

IPython >=4.0    :  6.1.0 (OK)
cython >=0.21    :  None (NOK)
jedi >=0.9.0     :  0.10.2 (OK)
nbconvert >=4.0  :  5.2.1 (OK)
numpy >=1.7      :  1.13.1 (OK)
pandas >=0.13.1  :  0.20.3 (OK)
pycodestyle >=2.3:  2.3.1 (OK)
pyflakes >=0.6.0 :  1.5.0 (OK)
pygments >=2.0   :  2.2.0 (OK)
pylint >=0.25    :  1.6.4 (OK)
qtconsole >=4.2.0:  4.3.0 (OK)
rope >=0.9.4     :  0.9.4-1 (OK)
sphinx >=0.6.6   :  1.6.2 (OK)
sympy >=0.7.3    :  1.1 (OK)



Discussion:
I'm sorry, I don't know what's happening in your case. We'll fix `SPYDER_DEBUG=3` on Windows for 3.2.1 so at least we can see what's preventing from `runfile` to be defined in the console.
@dalthviz, please work on this one.
I've tried a few more things and I believe now its an Anaconda issue. Uninstalled Anaconda and reinstalled it, but this time I updated Spyder only instead of doing conda update --all. This way I was able to run scripts just fine on Spyder 3.2 with runfile. I think something is breaking during conda update --all

The SPYDER_DEBUG = 3 still fails, though
> This way I was able to run scripts just fine on Spyder 3.2

Great! At least you found a workaround for your problem.

> The SPYDER_DEBUG = 3 still fails, though

Yeah, that's a known problem, but as I said, we'll fix it for 3.2.1.
@dalthviz, I think @gabrielclow last comment provided a way to reproduce this problem. Please create a new conda environment and install Anaconda there, like this

    conda create -n runfile-fix anaconda

Then run in that env

    conda update --all

and see if you can run scripts in Spyder or not.
@ccordoba12 I tested with the steps you provided but I was able to run a script
Ok, too bad...
Maybe the problem was the env where @gabrielclow tried to update with `conda update --all`?
I believe it was my env. I don't remember installing any pip packages but it's been some time. I still can't update everything because conda hangs and acts weird, but I think thats not Spyder at all because I'm using 3.2 normally now. Thanks for your help

Resolving patch:
diff --git a/spyder/app/mainwindow.py b/spyder/app/mainwindow.py
--- a/spyder/app/mainwindow.py
+++ b/spyder/app/mainwindow.py
@@ -3037,10 +3037,10 @@ def main():
     options, args = get_options()
 
     if set_attached_console_visible is not None:
-        set_attached_console_visible(DEBUG or options.show_console \
-                                     or options.reset_config_files \
-                                     or options.reset_to_defaults \
-                                     or options.optimize)
+        set_attached_console_visible(options.show_console
+                                     or options.reset_config_files
+                                     or options.reset_to_defaults
+                                     or options.optimize or bool(DEBUG))
 
     app = initialize()
     if options.reset_config_files:


Test patch: