Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need to press run twice with matplotlib in spyder #1831

Closed
spyder-bot opened this issue Feb 17, 2015 · 75 comments
Closed

Need to press run twice with matplotlib in spyder #1831

spyder-bot opened this issue Feb 17, 2015 · 75 comments

Comments

@spyder-bot
Copy link
Collaborator

From markfran...@gmail.com 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.
  2. Press run or F5 a second time and the script doesn't run
  3. 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

@spyder-bot
Copy link
Collaborator Author

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...

@spyder-bot
Copy link
Collaborator Author

From dive...@gmail.com 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.

@spyder-bot
Copy link
Collaborator Author

From dive...@gmail.com 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.

@spyder-bot
Copy link
Collaborator Author

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)

@spyder-bot
Copy link
Collaborator Author

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?

@spyder-bot
Copy link
Collaborator Author

From dive...@gmail.com 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.

@spyder-bot
Copy link
Collaborator Author

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: sylvain....@gmail.com

@spyder-bot
Copy link
Collaborator Author

From sylvain....@gmail.com on 2014-06-23T13:36:09Z

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

@spyder-bot
Copy link
Collaborator Author

From dive...@gmail.com 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...

@spyder-bot
Copy link
Collaborator Author

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.

@spyder-bot
Copy link
Collaborator Author

From sylvain....@gmail.com 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.

@spyder-bot
Copy link
Collaborator Author

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.

@spyder-bot
Copy link
Collaborator Author

From dive...@gmail.com 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.

@spyder-bot
Copy link
Collaborator Author

From sylvain....@gmail.com 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

@spyder-bot
Copy link
Collaborator Author

From dive...@gmail.com 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.

@spyder-bot
Copy link
Collaborator Author

From dive...@gmail.com 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.

@spyder-bot
Copy link
Collaborator Author

From dive...@gmail.com 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.

@spyder-bot
Copy link
Collaborator Author

From sylvain....@gmail.com on 2014-06-27T06:18:47Z

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

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2014-06-27T10:13:36Z

issue #1810 has been merged into this issue.

@spyder-bot
Copy link
Collaborator Author

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.

@spyder-bot
Copy link
Collaborator Author

From dive...@gmail.com 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.

@spyder-bot
Copy link
Collaborator Author

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.

@spyder-bot
Copy link
Collaborator Author

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).

@spyder-bot
Copy link
Collaborator Author

From dive...@gmail.com 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 .

@divenex
Copy link

divenex commented Sep 14, 2016

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

@ccordoba12
Copy link
Member

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

@ccordoba12
Copy link
Member

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

@divenex
Copy link

divenex commented Sep 27, 2016

@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.

@matthias2t
Copy link

@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 !

@ccordoba12
Copy link
Member

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

@brombeerberg
Copy link

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

@athompson673
Copy link
Contributor

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

@ccordoba12
Copy link
Member

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.

@divenex
Copy link

divenex commented Mar 10, 2017

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

@rpg32
Copy link

rpg32 commented Apr 15, 2017

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.

@ccordoba12
Copy link
Member

ccordoba12 commented Apr 15, 2017

@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.

@divenex
Copy link

divenex commented Apr 18, 2017

@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.

@ccordoba12
Copy link
Member

ccordoba12 commented Apr 19, 2017

@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.

@divenex
Copy link

divenex commented Apr 19, 2017

@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.

@ccordoba12
Copy link
Member

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants