Python Spyder: breakpoints working only once in a blue moon - python

I use Spyder 2.3.5.2 on an Anaconda Python installation running on Windows 7 64 bit.
The debug functionalities are very temperamental and unreliable. My breakpoints are often completely ignored. Sometimes applying the IT approach (closing and restarting the program) solves the issue, but more often than not it doesn't.
Some forums recommend running the program in the current ipython console, but that doesn't help, either.
Is there anything I can do?
Thanks.

I could not get Sypder to stop at break points (inserted with f12). But then in reading the docs I realized I needed to switch to debug mode (Ctrl-f5 or Debug->Debug). This switches the IPython console prompt to:
ipdb>
Once in this mode, break statements work.

Related

PyDev: Running code to interactive console

As my problem is quite simple I'll try to make this question simple aswell. The problem I'm having concerns the PyDev interactive console. I can bring up the console just fine without problems, and even use it as an interactive shell, just as I would be able to with IDLE. However, when I try to run my code that I've written in my project module, it won't run to the interactive console, but to the Eclipse default console. The default console displays the program just fine, but since it's not an interactive shell, I can't do anything afterwards.
With that being said, my question is: How do I get my code to run to the PyDev interactive console, and not the Eclipse default one? Thanks in advance!
For making the symbols of the current editor available in the interactive console, use Ctrl+Alt+Enter (which will do a runfile in the interactive console context).
Also, make sure you read: http://www.pydev.org/manual_adv_interactive_console.html
First it is possible. Second, off top of my head it might be you need to change in preferences where the debug perspective points to? Look through pydev preferences too. Sorry not to be more helpful. Away from computer.
Run the program from the code window. Try hitting F9 whike cyrsor in your code window. Results and bugs should show up in console.

Stopping running code

I'd like to stop code while running in Spyder, but ctrlc/ ctrlz nor cmdc/ cmdz does not work for me, even the blue stop button (normally used for debug).
I work under Yosemite 10.10.3 and am using Spyder 2.3.4 and Python 2.7
Has someone encountered the same issue?
The consoles both python and ipython, when executing code have a stop button in the top right corner of the panes.
The debug button has no business with that as you rightly said it is for debugging, so unless you are debugging you should not expect it to stop a non debugging session.

Spyder + PythonXY - Python Interpreter and IPython OUTPUT issues - no output

In Spyder (installed together with PythonXY) on a win 8 64 bit machine, both the Python interpreter and the IPython interpreter have output issues.
The first one, gives output at first but as soon as I run some particular code, it doesn't anymore. I noticed the issue happens easily if I get some error messages first, or if I use ipdb, but not only. Even with some code that run smoothly, it happens that it stops giving output afterward.
IPython is opened in a dedicated IPython console tab, although it's kernel opens a window in the console tab (this did not happen to me with previous versions of spyder and it all opened in the console tab). I need to input commands to the interpreter in the IPython console tab window, but the output is sent to the console tab window instead. Very annoying.
Anybody having the same issues? Solutions?
Thanks a lot!
Edit for Carlos Cordoba:
So, for example, in the normal Python interpreter I do:
import module
module.method1(par1)
where method1 has no errors in it. The method works fine and I get the right output. If I try method2 which contains an error, I get no output.
module.method2(par2)
After this, I get no output at all for any code I right. I have to restart the kernel.
I could not reproduce the same behavior right away on the "IPython console" window. It displays the error message correctly and the output keeps coming out correctly. However, if I use ipdb there, the output goes to the Kernel window instead of the console window, which is inconvenient.
Thank you!

Enthought Canopy doesn't print right away when statement occurs

A while ago I switched from Enthought's old EPD to their newer Canopy system. For the most part it's nice, but one aspect has been particularly vexing.
Whenever I run a python script, either from within the Canopy iPython environment or from the command line, none of my print statements actually get printed right away when that part of the script is hit. Instead, multiple prints seem to get executed all at once at a later time.
As an example...
import numpy as np
print "About to start long computation..."
a = np.random.randn(1e8)
print "Computation finished."
doesn't print the first statement until after a is finished being generated, when both statements are printed simultaneously. (You can tell when the calculation is occurring by watching the CPU monitor.)
Does anyone know what's going on here? If relevant, I'm running Canopy 1.0.0.1160, with Python 2.7.3 64bit on a Windows 7 machine.
This looks like buffered output. Try running your script as:
python -u yourscript
The -u flag turns buffering off.
(Replace python by your OS's python executable's name.)
No, this is not a change between EPD and Canopy. While I suppose there might be some python distributions which default to buffering off, EPD was not one of them -- the performance hit could have been too severe (as kindall's comment mentions.) Better to let the programmer decide when it's important for the user to see console output immediately (typically for status updates).
BTW, IPython in the Canopy GUI is simply IPython QtConsole. If you are depending on console I/O, you may also need to be aware of this longstanding issue with QtConsole:
I don't think there's a reasonable workaround for Canopy IPython, other than do it "properly", i.e. with flush.
https://support.enthought.com/entries/22157050-Canopy-Python-prompt-QtConsole-Can-t-run-interactive-OS-shell-commands

Cleanest way to run/debug python programs in windows

Python for Windows by default comes with IDLE, which is the barest-bones IDE I've ever encountered. For editing files, I'll stick to emacs, thank you very much.
However, I want to run programs in some other shell than the crappy windows command prompt, which can't be widened to more than 80 characters.
IDLE lets me run programs in it if I open the file, then hit F5 (to go Run-> Run Module). I would rather like to just "run" the command, rather than going through the rigmarole of closing the emacs file, loading the IDLE file, etc. A scan of google and the IDLE docs doesn't seem to give much help about using IDLE's shell but not it's IDE.
Any advice from the stack overflow guys? Ideally I'd either like
advice on running programs using IDLE's shell
advice on other ways to run python programs in windows outside of IDLE or "cmd".
Thanks,
/YGA
For an interactive interpreter, nothing beats IPython. It's superb. It's also free and open source. On Windows, you'll want to install the readline library. Instructions for that are on the IPython installation documentation.
Winpdb is my Python debugger of choice. It's free, open source, and cross platform (using wxWidgets for the GUI). I wrote a tutorial on how to use Winpdb to help get people started on using graphical debuggers.
You can easily widen the Windows console by doing the following:
click the icon for the console window in the upper right
select Properties from the menu
click the Layout tab
change the Window Size > Width to 140
This can also be saved universally by changing the Defaults on the menu.
Year 2017-2022 Answer:
Try Visual Studio Code, it has great support for Python debugging, auto completion and more!
See this link for details:
https://code.visualstudio.com/docs/languages/python#_debugging
However, I want to run programs in
some other shell than the crappy
windows command prompt, which can't be
widened to more than 80 characters.
Click on the system box (top-left) in the command prompt and click properties. In the layout tab you can set the width and height of the window and the width and height of the screen buffer. I recommend setting the screen buffer height to 9999 so you can scroll back through a long output.
I use eclipse with pydev. Eclipse can be sluggish, but I've become attached to integrated svn/cvs, block indent/unindent and run as unittest features. (Also has F5 run)
If your comfortable in emacs though I don't see any reason to make such a major change.
I suggest instead that you replace your 'crappy command prompt' with powershell. It's not as crappy.
(As mentioned by Soviut and The Dark - you can increase the buffer width/window size to more than 80 by title-bar>right-click>Properties>Buffer Width/Window Size edit even in crappy cmd)
Wing IDE is awesome. They also have a free version.
If you ever graduate to vim, you can just run the following command to start the program you're currently editing in an interactive shell:
:!python -i my_script.py
I edit my Python programs in EditPlus. I've configured a user tool that allows me to run my program and have its output appear in a frame below my editor window. My configuration will even let you double click on an exception lines in the output to jump directly to the file and line where the error occurred. You can grab the user tool configuration I use from here on the EditPlus wiki.
Perhaps there is similar functionality you can configure that allows you to run your program and display its output in your Emacs editor!?
I replaced cmd with Cygwin and Poderosa. May be a little overkill though, if the only problem you have with cmd is that it's a pain to resize.
Although you use Emacs instead of Vim, so I guess you're into overkill... ;-)

Categories