Spyder: Need to press run twice with matplotlib in spyder

Created on 17 Feb 2015  Â·  75Comments  Â·  Source: spyder-ide/spyder

_From [email protected] on 2014-05-26T19:10:46Z_

Spyder Version: 2.3.0beta2
Python Version: 3.3.5
Qt Version : 4.8.4, PyQt4 (API v2) 4.9.6 on Windows
pyflakes >=0.6.0: None (OK)
pep8 >=0.6 : None (NOK)
IPython >=0.13 : 2.0.0 (OK)
rope >=0.9.2 : 0.9.4 (OK)
sphinx >=0.6.6 : 1.2.2 (OK)
matplotlib >=1.0: 1.3.1 (OK)
sympy >=0.7.0 : 0.7.5 (OK)
pylint >=0.25 : 1.1.0 (OK)

What steps will reproduce the problem?

  1. Open a script with a matplotlib figure. For example one from the matplotlib site. http://matplotlib.org/mpl_examples/pylab_examples/figure_title.py 2. Press run or F5. It runs normally.

    1. Press run or F5 a second time and the script doesn't run

    2. Press run or F5 a third time then the script runs

What is the expected output? What do you see instead?

When you try to run a script with matplotlib you press run and it works normally the first time. Press run again and the script doesn't run. You have to hit run a second time in order for the script to run

Spyder is in "Execute in current python or ipython interpreter" mode

In the console it looks like this (i removed the file paths to make it shorter). F5 puts the runfile in. The second time you try to run it, when you click F5 or the green run arrow twice you runfile goes into the console twice before it runs.

">>> runfile('C:/.../figure_title.py', wdir=r'C:/...')

runfile('C:/.../figure_title.py', wdir=r'C:/...')
runfile('C:/.../figure_title.py', wdir=r'C:/...')
"

Please provide any additional information below

. I thought it was a problem with my own script, but the problem repeats even with code from the matplotlib website.

I only have this problem when I have a script with matplotlib. For example, when I run a simple script like below I can run it over and over no problem. I never have to press F5 twice.

x = int(input("enter an number: "))

if x < 0:
x = 0
print('Negative')
elif x > 0:
print('Positive')
elif x == 0:
print('Zero')

_Original issue: http://code.google.com/p/spyderlib/issues/detail?id=1831_

6–10 stars Windows Python Console Bug

Most helpful comment

The bad behaviour described in the first comment of this issue seems to be still persistent. The two problems are:

  1. Scripts aren't running when 'Runf File' resp. F5 is pressed. One has to press it either twice or press enter in the console after the first F5
  2. When changing to another script the previous script is run after the procedure described in 1.

In my case all this started after updating from spyder 2 to 3.
My configuration is:

  • Windows 7, 64 bit
  • Python 2.7.12
  • Anaconda 4.2.0
  • Spyder 3.0.2
  • in the preferences run is set to "execute in current Python or IPython console"
  • the current console is Python

All 75 comments

_From contrebasse on 2014-05-27T00:28:48Z_

Are you in interactive mode or do you call show() at the end of your script ? The show() call is blocking and it could explain why the script doesn't run the second time. However it doesn't explain why it would run fine the third time...

_From [email protected] on 2014-05-28T05:15:05Z_

I have the same problem after installing Spyder 2.3.0rc, with the same configuration as markfran. I note however that the problem is present when pressing F5 from a Python console, but _not_ from an IPython one.

_From [email protected] on 2014-06-02T07:31:12Z_

Changing interactive mode with plt.ion() or plt.ioff() does not affect this bug.

I typically use interactive mode and my procedures show plots without using the plt.show() command. But if I call plt.ioff() before calling my matplotlib procedure, the "press-run-twice" bug appears even if my procedure did not actually show any plot.

In summary, as long as I first call from the Python console a procedure which uses a matplotlib function, I need to press run twice to run any subsequent procedure.

_From ccordoba12 on 2014-06-22T20:57:01Z_

I can't reproduce this in Python 2. Maybe it's an error with Python 3 and Matplotlib, I'm going to check it out.

Summary: Need to press run twice with matplotlib in spyder (was: need to press run twice with matplotlib in spyder)

_From ccordoba12 on 2014-06-22T22:38:09Z_

I have two questions for you (just out of curiousity):

  1. How did you install Matplotlib?
  2. Are you using WinPython or Anaconda?

_From [email protected] on 2014-06-23T04:24:03Z_

I tried two different distributions:

  1. I uninstalled Spyder from WinPython 3.3.5 64bit and replaced it with Spyder 2.3.0rc
  2. I used the latest Anaconda distribution with Python 3.4 64bit, which comes with Spyder 2.3.0rc

The above bug behaves in the same way in both distributions.

_From ccordoba12 on 2014-06-23T13:15:02Z_

No luck at reproducing this one for me after several hours of work :) I installed the latest Anaconda for 32bit and everything is working as expected (I don't have Win64 to test on).

I was also unable to verify issue #1837 and issue #1861 , so I don't see any of them as showstoppers for 2.3, sorry.

Maybe you would be better by using IPython instead of plain Python, because IPython guys have worked really hard to smooth all interactions with Matplotlib.

@-Sylvain, if you have some free time and access to Win64, could test it just to be sure?

Cc: [email protected]

_From [email protected] on 2014-06-23T13:36:09Z_

Ok I can look into it tonight. I have a win64 at hand. S.

_From [email protected] on 2014-06-23T15:41:09Z_

@-ccordoba12 thank you very much for looking into this, and in general for your great work on improving spyder. I love it!

My main reason for _not_ using an IPython console with spyder is the lack of a history buffer during debugging. The history only works for me during debugging in the normal Python Console. I am not sure this is intended/expected, or I am doing something wrong...

_From ccordoba12 on 2014-06-23T15:53:04Z_

I understand your point about IPython. That's a technical limitation on its side, so (unfortunately) we can't do anything about it.

You could also try to test your issues in another machine, just to be sure if they are related to Win64 or to your particular setup.

_From [email protected] on 2014-06-23T16:40:11Z_

Hi, I don't reproduce the described behavior with the current tip of the default branch, with Win7 64bits. Local version of PyQt is 4.10.4.

A problem that I have experienced with windows in general is that the matplotlib window is created and remains hidden behind the Spyder window.

_From ccordoba12 on 2014-06-24T04:29:29Z_

Yes, that's a terrible nuisance that hopefully one day mpl devs fix :)

Thanks for your help Sylvain.

_From [email protected] on 2014-06-24T13:39:59Z_

@-Sylvain just to be sure, did you try to reproduce this bug on Python 3.3 on Windows?

I only have this bug with Python 3.3, but the same Spyder 2.3.0rc work well for me with Python 2.7.

_From [email protected] on 2014-06-24T14:36:14Z_

Indeed it seems to be a Python 3 specific thing. I will need to test it in a different environment. (Besides, the booststrap script does not seem to work with Python 3)
Sylvain

_From [email protected] on 2014-06-24T15:23:12Z_

I also had problems using the booststrap.py script with Python 3. It failed to start. I wanted to be sure I could reproduce the bug with the latest Spyder version.

After deleting "C:\Users\myname.spyder2-py3" a few times, Spyder eventually started and gave me the same bug as with the officially released and normally installed 2.3.0rc version.

_From [email protected] on 2014-06-26T03:16:32Z_

@ccordoba12 and @-Sylvain I noted that issue #1810 is also the same as this issue #1831 . So it appears this bug was confirmed by at least three different people on different computer and configurations.

It appears to be there since Spyder 2.3.0beta2. In all cases the bug appears only under Python 3, whose support is one of the highlights of Spyder 2.3. The bug, with the related issue #1837 and issue #1861 makes the Python Console essentially unusable under Python 3.

These issues force one to use IPython for debugging in Spyder, which implies one has to loose the command history.

I would vote for raising the priority of this related series of issues, if Spyder 2.3 intends to support Python 3.

_From [email protected] on 2014-06-27T04:48:19Z_

I did an additional test, which may help locate the source of the problems.

I just downloaded the latest Spyder version from the repository and I used bootstrap.py to start it under Python 2.7.6 (WinPython 64bit).

I then went to Preferences/Console/Advanced_settings/Python_Executable and at the section "Use the following Python interpreter" I selected Python 3.3.5.

I can confirm that issue #1810 , issue #1831 , issue #1837 and issue #1861 all still apply when I run, compile or debug programs on a Python 3 console, even when running Spyder under Python 2. Hopefully this test will help with finding a solution.

_From [email protected] on 2014-06-27T06:18:47Z_

@-divenex, thank you for investigating this further. I will look further into it tonight.

_From ccordoba12 on 2014-06-27T10:13:36Z_

issue #1810 has been merged into this issue.

_From ccordoba12 on 2014-06-27T10:24:59Z_

A couple of comments:

  1. @-divenex: We can't raise the priority of these issues (and so block the final release) if we are unable to reproduce them. As I said, I spent like 5 hours last weekend trying to do it and was unable to. Besides using Anaconda, I installed Python 3.3 from python.org, PyQt, numpy and matplotlib from their official installers and no luck at all. So what else can we do?
  2. @-Sylvain: Please let me know what's the problem with bootstrap.py and Python 3. I'm not seeing problems on Windows or Linux.

_From [email protected] on 2014-06-27T10:42:58Z_

@-ccordoba12 thanks a lot for the tests.

I really hoped you could reproduce it, as I can't make it go away no matter what I try, on the two Windows (7 and 8) 64bit computers and two distributions (WinPython and Anaconda) I have tried. And two other users reported it...

But of course I understand that it's impossible for you to fix it without seeing the bug on your machine.

_From ccordoba12 on 2014-06-27T10:59:08Z_

Sigh, I'll see if I can borrow a Win64 this weekend. But even if I could confirm it, I think we should release with what we have because this seems pretty subtle and hard to debug, so solving it could take us two weeks or more.

_From ccordoba12 on 2014-06-27T22:46:38Z_

Just a hunch but could you try to deactivate your firewall/antivirus and run everything again to see what happens?

Maybe they are interfering with the communication between Spyder and the process where code is run (which is external to Spyder so as not blocking the GUI).

_From [email protected] on 2014-06-28T05:12:29Z_

Thanks for the suggestion. I tried to disable both firewall and antivirus but unfortunately nothing changes. All reported bugs are still here.

As one more test I installed the 32bit version of WinPython 3.3.5.0. I can confirm that the issue #1831 , issue #1837 and issue #1861 are still there also with 32bit Python 3 under Windows.

This is true both when running with boostrap.py the latest Spyder 2.3.0rc version from the repository and when running the Spyder 2.3.0beta2, which comes preinstalled with WinPython 3.3.5.0.

The latter agrees with what originally reported by markfran, who started issue #1831 and with sstef, who opened issue #1810 .

_From ccordoba12 on 2014-07-06T06:16:48Z_

Ok, that's progress! At least you narrowed down the problem to Windows 8. Unfortunately I don't have access to a Win 8 machine, so someone else will have to help us here.

Labels: OpSys-Windows

_From ccordoba12 on 2014-07-06T09:56:51Z_

It seems you found the solution being some issue with WinPython. If that's the case then we could close these issues and you could move the discussion to WinPython bug tracker.

_From [email protected] on 2014-07-06T10:19:35Z_

I made a clean install of Windows 8.1 64bit in a virtual machine. I did not install anything except for Anaconda 2.01 64bit version with Python 3.4, which includes Spyder 2.3.0rc.

Unfortunately I have to confirm that issue #1831 , issue #1837 and issue #1861 are still there with a completely clean and standard configuration of Windows 8.

(@ccordoba12 apologies for my too quick and incorrect report that the problem may have been solved.)

_From [email protected] on 2014-07-06T10:40:46Z_

As additional info: with a fresh install of Windows 8.1 and Anaconda3, the first time I run a matplotlib script, it run correctly every time I press F5 as it should. This made me think the bug was finally gone!

But as soon as I created other scripts and started to switch from one to the other, I realized that issue #1831 , issue #1837 and issue #1861 were still there.

_From [email protected] on 2014-07-07T05:57:33Z_

I experience this issue as well. I am running Win7 64bit and am running Spyder from WinPython 3.3.5. Based on the comments for this issue, and mine and my colleages experience, this seems to be something specific to the Python 3.x version of WinPython.

Here's an example of my console output (the runfile line must come from pressing the Run file button, otherwise the error does not occur):

print('test')
test
runfile('C:/path/to/file.py', wdir=r'C:/path/to')

UMD has deleted: rosapreaders, helpers, plot_fft

test

print('test')

test

_From [email protected] on 2014-07-07T07:34:06Z_

@-Jason thanks for reporting this. It's very useful to know it also happens on Win7 to you and your colleagues, and not just on Win8.

I agree this is specific to Python 3, but note that this is not specific to WinPython, as I also have the same problems with Anaconda3.

I plan to test it on a clean install of Win7+Anaconda, as I did with Win8, to see if it also happens there. I am trying to nail down the conditions in which this series of bugs happens, hoping to help the developers in reproducing/fixing this.

I love Spyder, but with this issue I can't consider it yet a viable alternative for Python 3, which is where I hope the community is finally leading...

_From [email protected] on 2014-07-08T08:20:44Z_

I made a clean install of Windows 7 64bit in a virtual machine. I did not install _anything_ else except for (i) Anaconda3 2.01 64bit version with Python 3.4, which includes Spyder 2.3.0rc; (ii) WinPython 3.3.5, which includes Spyder 2.3.0beta2.

I confirm that all issue #1810 , issue #1831 , issue #1837 and issue #1861 still apply to the most popular completely clean and standard configuration of Windows. The same applies, as I reported in my earlier comment, with a clean install of Winodws 8.1 64bit.

I give below some detailed examples under Windows 7 and Anaconda3, but the same happens under Windows 8 and/or WinPython.


As an example of issue #1831 ---------------------------

Given the following trivial script temp1.py:

import numpy as np
import matplotlib.pyplot as plt
plt.plot(np.arange(5))
print("first script")

If I start a new Python console and press F5 three times I get the following output on the console:

Python 3.4.1 |Anaconda 2.0.1 (64-bit)| (default, Jun 11 2014, 17:27:11) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
\>>> runfile('C:/dir/temp1.py', wdir=r'C:/dir')
first script
\>>> runfile('C:/dir/temp1.py', wdir=r'C:/dir')
runfile('C:/dir/temp1.py', wdir=r'C:/dir')
first script
\>>> 

Note that the application runs correctly the first time, but required two F5 the second time as originally reported for issue #1831 .


As an example of issue #1861 ---------------------------

If I now open a second similar script temp2.py

import numpy as np
import matplotlib.pyplot as plt
plt.plot(np.arange(5))
print("second script")

And press F5 _four_ times I get the following output:

\>>> runfile('C:/dir/temp2.py', wdir=r'C:/dir')
runfile('C:/dir/temp2.py', wdir=r'C:/dir')
first script
\>>> runfile('C:/dir/temp2.py', wdir=r'C:/dir')
runfile('C:/dir/temp2.py', wdir=r'C:/dir')
second script
\>>> 

Note that only after pressing F5 _four_ times temp2.py finally runs. The first two F5 presses only execute the previously active script temp1.py, even tough the console writes runfile(...temp2.py...)


As an example of issue #1837 ---------------------------

An even more serious problem is the fact that if I place a breakpoint on the third line of the temp1.py and press Ctrl+F5 to "debug file" I get the following output. Note that the console gives no prompt, contrary to what it should.

\>>> debugfile('C:/dir/temp1.py', wdir=r'C:/dir')

When I press Ctrl+F12 to "continue execution until the next breakpoint", the execution skips to the end, instead of stopping at the breakpoint

continue
first script
\>>>

BOTTOM LINE

The Python console is basically unusable in Spyder 2.3.0rc, when using Python 3 under Windows 7 or 8. Only the IPython console works there.

Given that all the bugs apply with clean install of the operating systems, many users of Python 3 are likely to be affected.

I wish I could help. I am experienced with Python, but I would not know where to start with debugging Spyder... But I hope my tests will make it easy for one of the developers to reproduce the problems. (For info, in my tests I used a free VMware virtual machine and I did not need to activate the operating systems when installing Windows 7/8, as Windows will work in trial mode for 30 days)

_From [email protected] on 2014-07-22T05:01:19Z_

I have the issue of scripts not running on the second F5 as well.
Setup: win7 64 bit, installed everything via WinPython.

I noticed that when I type 'runfile([scriptname])' manually, everything works fine. Here is a console session demonstrating the effect (personal info from path removed):

Python 3.3.5 (v3.3.5:62cf4e77f785, Mar 9 2014, 10:35:05) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

Imported NumPy 1.8.1, SciPy 0.13.3, Matplotlib 1.3.1

  • guidata 1.6.1, guiqwt 2.3.2
    Type "scientific" for more details.

runfile('C:/[somepath]/TransmissionProbability.py', wdir=r'C:/[somepath]')
# This was with F5, works flawlessly
runfile('TransmissionProbability.py')
# Manually typed: works perfect (my working directory was set correctly)
runfile('C:/[somepath]/TransmissionProbability.py', wdir=r'C:/[somepath]')
# F5 again, this hangs (until second F5 but I didn't do that). I press Ctr-C to break the hang, output:

Traceback (most recent call last):
File "_ctypes/callbacks.c", line 260, in 'calling callback function'
File "C:\path\to\WinPython\WinPython-64bit-3.3.5.0\python-3.3.5.amd64\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 295, in qt_inputhook
QtCore.QCoreApplication.exec_()
KeyboardInterrupt

Hopefully this is helpful. My workaround now is to restart the python console for every run, but I loose figures then, which is a bit inconvenient.

_From ccordoba12 on 2014-07-24T08:08:03Z_

Thanks a lot for the additional info @-boukekrom. Could some of you guys go to

Preferences > Console > External modules > Qt (PyQt/PySide)

and _deactivate_ the option called

Install Spyder's input hook for Qt

to see if that helps or fixes your problem?

Cc: [email protected]

_From [email protected] on 2014-07-25T10:39:49Z_

@-ccordoba12 thanks for looking into this. Unfortunately what you suggests does not solve the problem.

With the released version of Spyder 2.3 and Python 3.3, if I _deactivate_ the option called "Install Spyder's input hook for Qt" then the procedure runs the very first time I press F5 as before.

However things change afterwards. Now pressing F5 again any number of times does not run the procedure any more, it simply prints on the console and never gives the prompt back:

runfile('C:/dir/temp1.py', wdir=r'C:/dir')
runfile('C:/dir/temp1.py', wdir=r'C:/dir')
runfile('C:/dir/temp1.py', wdir=r'C:/dir')
runfile('C:/dir/temp1.py', wdir=r'C:/dir')
runfile('C:/dir/temp1.py', wdir=r'C:/dir')
...

_From ccordoba12 on 2014-08-08T04:53:50Z_

issue #1925 has been merged into this issue.

_From ccordoba12 on 2014-08-08T17:20:28Z_

I finally was able to test and confirm this bug (along with the other ones referenced by @-divenex).

The only solution I've found so far is to use a different Matplotlib backend. You can change it in:

Preferences > Console > External modules > Matplotlib

from the default (Qt4Agg) to TkAgg (the only other available on Windows).

Unfortunately this doesn't work for those of you that work with Anaconda. I'll try to fix that for the next Anaconda release.

Status: Accepted

_From ccordoba12 on 2014-08-08T17:21:21Z_

issue #1837 has been merged into this issue.

_From ccordoba12 on 2014-08-08T17:21:53Z_

issue #1861 has been merged into this issue.

_From [email protected] on 2014-08-11T04:12:06Z_

@-ccordoba12 great you were able to confirm this! I really miss the Python console in Spyder!

Your solution partially works work me. It solves the reported issues but it produce another one: with the TkAgg backend the graphics window now constantly says "(Not Responding)".

More specifically, when I run the following script

import numpy as np
import matplotlib.pyplot as plt
plt.plot(np.arange(5))
print("first script")

the procedure does run correctly every time I press F5, and debugging also works. However no plot appears on the screen, until I type something like "plt.pause(99)".

Moreover the Tk window is constantly unresponsive so I cannot easily bring it to the foreground, unless I again type "plt.pause(99)".

In summary the Tk windows behaves exactly in the same way as it does during debugging (see issue #620 ), even when I am _not_ debugging any script.

Is there any configuration that can fix this behaviour (I am using WinPython with Python 3.3.5 and Spyder 2.3.0)?

_From [email protected] on 2014-08-11T06:13:19Z_

@-ccordoba12 I confirm that using the latest Anaconda one cannot select the TkAgg backend as Spyder gives the following long error message when trying to run e.g. the above temp1.py short script. Note that the Tk graphics windows still says "(Not Responding)" as it does using WinPython (see my previous comment):

Python 3.4.1 |Anaconda 2.0.1 (64-bit)| (default, Jun 11 2014, 17:27:11) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

runfile('C:/dir/temp1.py', wdir=r'C:/dir')
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Usersxxx\Anaconda3\lib\site-packages\matplotlib\backends\tkagg.py", line 13, in blit
tk.call("PyAggImagePhoto", photoimage, id(aggimage), colormode, id(bbox_array))
_tkinter.TclError: invalid command name "PyAggImagePhoto"

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Usersxxx\Anaconda3\lib\tkinter__init__.py", line 1487, in call
return self.func(*args)
File "C:\Usersxxx\Anaconda3\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 276, in resize
self.show()
File "C:\Usersxxx\Anaconda3\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 349, in draw
tkagg.blit(self._tkphoto, self.renderer._renderer, colormode=2)
File "C:\Usersxxx\Anaconda3\lib\site-packages\matplotlib\backends\tkagg.py", line 20, in blit
tk.call("PyAggImagePhoto", photoimage, id(aggimage), colormode, id(bbox_array))
_tkinter.TclError
first script

_From ccordoba12 on 2014-08-11T15:16:42Z_

@-divenex: What happens if you try to use a 32 bits Anaconda installation instead of the 64 one? Does the same behavior still shows?

_From [email protected] on 2014-08-12T12:51:22Z_

@-ccordoba12 Doing exactly the same on the 32bit version of Anaconda3, Python crashes when I run the temp1.py script: "the program stopped working"

_From ccordoba12 on 2014-08-13T10:53:34Z_

@-divenex:

  1. AFAICT the error with Anaconda is a bug with their matplotlib build, so it has to be reported with them so they can fix it.
  2. If TkAgg plots are unresponsive (with WinPython, I mean), this means that there's _something_ that is interrupting the communication between the Spyder graphical interface and the external Python process used to run code (which is done via sockets). It could be a firewall, and antivirus or something like that, because I wasn't able to reproduce this problem in another 64 bits Win 7 machine with Anaconda3 and the Qt4Agg backend.

Until we find what's that something and how to avoid the communication issue it's introducing, there is no workaround or configuration change that can be used to change the situation.

  1. I'm sorry to say it but this is way beyond my league in terms of OS (I'm a Linux guy) and expertise (I've worked very little with sockets). So we'll have to wait until Pierre (the Spyder author and Windows expert) comes back and tackles this issue, or other person with similar skills.

Owner: pierre.raybaut
Labels: Cat-Console

_From [email protected] on 2014-08-13T12:10:35Z_

@-ccordoba12 thank you for the explanation. Then I really hope Pierre can have a look at this issue and bring the Spyder Python console to the Windows users of Python 3 too.

I really like Spyder and can't work without it. So, since I moved to Python 3, I have been tempted many times to go back to Python 2.7, where Spyder worked well. But I think it's time for the community to start embracing Python 3. For this reason I stick to it and hope someone can figure out how to solve the problems. Unfortunately I cannot be of much help myself with this specific issue...

_From [email protected] on 2014-08-15T00:16:39Z_

I came across the same problem with @-divenex, and this drives me mad. Hope Pierre fix it.

_From [email protected] on 2014-11-05T10:47:23Z_

Hi All,

I have installed WinPython-64bit-3.3.5.0 on my Windows 8.1 machine
I think I may hit issue related with what you are discussing which I can reproduce very easy. I have file with the following content

def msgBox(caption,title='Information',buttons=['OK']):
'''Displays a modal message box.
Arguments:
caption: message text
title: titlebar text
buttons: list or tuple of buttons label texts

The message box icon is set by a keyword in the title.
Following keywords are recognized: 
    'info' or 'about',
    'critical' or 'error,
    'warning' or 'caution',
    'question' or 'confirm'.
Where each keyword of these pairs is fully equivalent.

Up to three buttons can be specified, using a tuple or list of button labels.

Example:
    import PYnGUInLib as GUI
    reply=GUI.msgBox('Do you want to abort?','Question',['Abort','Continue','Restart'])

If no buttons are specified, there is one "OK" button by default.

The message box closes when a button is pressed, and the
label of the button that was pressed is returned.
'''

app=QtGui.QApplication.instance()   # checks if QApplication already exists 
if not app:                         # create QApplication if it doesnt exist 
    app = QtGui.QApplication(sys.argv)


mb=QtGui.QMessageBox()
mb.setStyleSheet("background-color: rgb(241, 241, 241);");

mb.setText(caption)
mb.setWindowTitle(title)
for str in buttons:
    mb.addButton(str, QtGui.QMessageBox.AcceptRole)

if 'info' in title.lower() or 'about' in title.lower():
    mb.setIcon(QtGui.QMessageBox.Information)
elif 'critical' in title.lower() or 'error' in title.lower():
    mb.setIcon(QtGui.QMessageBox.Critical)
elif 'warning' in title.lower() or 'caution' in title.lower():
    mb.setIcon(QtGui.QMessageBox.Warning)
elif 'question' in title.lower() or 'confirm' in title.lower():
    mb.setIcon(QtGui.QMessageBox.Question)
else:
    mb.setIcon(QtGui.QMessageBox.Information) 

return buttons[mb.exec_()]

import PYnGUInLib as GUI
reply=GUI.msgBox('Do you want to abort?','Question',['Abort','Continue','Restart'])

at this point I get my message box if I hit for exmample a space in the Spyder console before hiting one of the buttons of my message box it seems something happens. So after that I get this behaviour: (have to press enter sometimes 2 tiomes, somethimes 5,6 times before getting the result)

2+2

4

_From [email protected] on 2014-11-05T10:51:41Z_

I've just noticed the amount of enters required (to get 4) depends of how many spaces I have entered before hiting a message box button.

_From ccordoba12 on 2015-01-01T15:47:59Z_

issue #1597 has been merged into this issue.

_From [email protected] on 2015-02-03T23:16:37Z_

In Spyder 2.3.2, this bug, which initially appeared specific to Windows, can now be reproduced also using Python 3.4 (Anaconda) under Ubuntu (14.04 64bit).

It would be great if somebody was able to fix this major and long-standing bug. Alternatively the console should be disabled under Python 3 to make clear it is not supported there.

_From ccordoba12 on 2015-02-04T07:28:07Z_

This is more serious. So this code

import numpy as np
import matplotlib.pyplot as plt
plt.plot(np.arange(5))
print("first script")

also gives problems on Ubuntu?

_From [email protected] on 2015-02-04T13:51:24Z_

Yes, I confirm that I need to press twice to run the above simple script in the standard console with Spyder 2.3.2 under Ubuntu.

All the previously reported issues related to this annoying bug, which make it impossible to debug in the console, are also present under Ubuntu with Python 3.

_From ccordoba12 on 2015-02-04T14:59:28Z_

Bad, bad, bad. Unfortunately 2.3.3 is almost ready, so I'll see what I can about it for 2.3.4

Labels: MS-v2.3.4

_From [email protected] on 2015-02-05T01:52:25Z_

I have the impression the Spyder developers have yet to make the transition to Python 3, otherwise they would realize how buggy Spyder looks under Python 3. Should one not try to make the console usable in Python 3 before making more Spyder official releases?

Note that I do understand that fixing that bug is difficult, otherwise it would not have eluded a solution for almost a year! But I feel this fix should have top priority and the person who fixes it should get a prize...

_From ccordoba12 on 2015-02-05T16:09:11Z_

I introduced this bug on Linux while trying to fix issue #1930 (which was very serious too). It took me a couple of hours to understand what was happening with the interaction of both problems.

In any case, thanks for your insistence. At least I think I have a fix for Linux, which I'll include in 2.3.3.

_From [email protected] on 2015-02-06T00:32:27Z_

That's interesting. If you can fix on Linux, don't you think something similar can fix on Windows too? The symptoms of the problem now look very similar on Linux and Windows...

_From ccordoba12 on 2015-02-09T06:38:30Z_

I think I fixed issue #2022 as part of the efforts to fix this one. Please test the latest mercurial version and let me know if it's working for you or not.

@divenex, after many hours spent on this issue, I can say that it's very tricky and far from trivial to fix on Windows.

I'll consult some friends to try to solve it for 2.4. Sorry for the bad news.

hi,

Going back to initial problem.
with spyder launching in the current python IDE style console

When it doesn't run, i go to the console, and I type:

  • <ENTER> the first time the non-display problem occurs,
  • 2 times <ENTER> the second time the non-display problem occurs,
  • 3 times <ENTER> the third time the non-display problem occurs,
  • 4 times <ENTER> the forth time the non-display problem occurs, ....

and then , the graphic then displays itself, it works (even if I have typed on the next blank prompt lines, stupidly).

(spyder 2.3.3, python 2.3.4, windows)

@ccordoba12 thanks for trying.

I must report this long standing bug is still there in 3.0.0b6.

Sorry, I really don't know how to solve this bug. Have you tried with Qt5? Does this bug appear with it too?

@divenex, I think I found a fix for this problem (after some experimentation :-) Will you be able to test it from a pull request?

@ccordoba12 sorry for my slow reply. I have now tested Spyder 3.0.0 with QT5 (qt: 5.6.0) and the problem is still there. The Python console is still completely unusable, and only the IPython console works. This is for Anaconda with Python 3.5 under Windows 10 64bit.

@ccordoba12
Sorry for the duplicated report. In case it could help, on my side, same configuration than divenex. I had to go back to version 3.0.0b6 (with exact same dependencies) to have it work. On the 3.0.0b7, the run command itself is not found, I got an error message.
Thanks for your work anyway !

Yes, the problems with b7 were fixed in the final release.

The bad behaviour described in the first comment of this issue seems to be still persistent. The two problems are:

  1. Scripts aren't running when 'Runf File' resp. F5 is pressed. One has to press it either twice or press enter in the console after the first F5
  2. When changing to another script the previous script is run after the procedure described in 1.

In my case all this started after updating from spyder 2 to 3.
My configuration is:

  • Windows 7, 64 bit
  • Python 2.7.12
  • Anaconda 4.2.0
  • Spyder 3.0.2
  • in the preferences run is set to "execute in current Python or IPython console"
  • the current console is Python

Just want to bump this issue, and add something I haven't seen others mention..

With a fresh console, anything entered interactively returns immediately:

>>> 2+2
4

As others have stated running the current file with f5 requires clicking back to the console and hitting <return> again. After this all interactive entries also require an extra <return>:

>>> 2+2
>>> 
4

Running the file again continually increments the number of times I have to hit <return> to get a response back from the interpreter:

>>> 2+2
>>> 
>>>
>>>
>>>
>>>
4

I'm sorry but the Python console is going to be removed in Spyder 3.2, so we don't plan to fix this or any other bug related to it.

I'll create an issue explaining our reasons to do that, but one of the main ones is that the Python console is broken on Windows.

Let's not forget that the Python console is the only one that currently supports a command history during debugging. So I would not remove the Python console before implementing the command history in the IPython one.

I am still wondering how people can tolerate debugging in Spyder using the IPython console, without a command history!

FYI: The Linux version of Spyder, with a working Python console, can be used in Windows 10 with the Windows Subsystem for Linux

That is sad to hear that the Python console is going to be removed! I use that exclusively.

I have been having the same problem with the delayed execution after upgrading to Anaconda (1.5) and Spyder (3.1.3) with Python (3.6).

There is a simple workaround for those who wish to have similar functionality with the console while avoiding the delayed execution. Maybe it will help others.

Just go to the Run>Configure. Then in the 'Console' group switch from 'Execute in current Python or IPython console' to 'Execute in new dedicated Python console'.

I also checked 'Interact with the Python console after execution' and 'Show warning when killing running process'.

It is maybe not the best work around but at least it gets rid of the delayed execution.

@rpg32, unfortunately the Python console is holding us back on several fronts, and it's really unmaintained right now (I've done my best to fix its bugs throughout the years, but it's very hard to debug).

However, let me assure you that we will migrate all its features to the IPython console so that people don't miss a thing about it in 3.2.

@ccordoba12 it is great to hear you plan to migrate the Python Console features to the IPython one. In that case, it makes full sense to consolidate development onto a single console. I am looking forward to 3.2 then.

@divenex, that's the idea. I just added history browsing while debugging to the IPython console on PR #4202, so that would solve your major complaint about it.

Other missing functionality (e.g. running a file in a dedicated IPython console) will come in other PRs.

@ccordoba12 you are right, history browsing while debugging is indeed the only feature I have been missing in the IPython console. Excellent to see a PR about it.

Closing because the Python console is going to be removed in Spyder 3.2.

Please see issue #4524 for our reasons to do this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

goanpeca picture goanpeca  Â·  106Comments

spyder-bot picture spyder-bot  Â·  47Comments

jzzhou715 picture jzzhou715  Â·  64Comments

spyder-bot picture spyder-bot  Â·  55Comments

batuhandayioglugil picture batuhandayioglugil  Â·  72Comments