Is it possible to hit graphical breakpoints when running codes in PyCharm's IPython console?
i.e.:
You have a script foo() in foo.py
You place a graphical breakpoint inside foo() from the editor (the red dot next to line number)
You import foo into a PyCharm's IPython console and execute foo() (Note: not running from a debug configuration!)
As suggested by #bvanlew in comments, PyCharm (both community and professional edition) now supports attaching debugger onto interactive console. Click the debug button as shown below, and PyCharm's debugger will kick in when the breakpoint is hit.
Yes, it is. But it is not automatic.
(Using 4.5.2, Windows 8)
I run an IPython Notebook, and let PyCharm kick off the notebook backend.
I hit Tools, Attach to Process and attempt to identify the PID of the notebook process. I'm yet to find a smooth way of doing this. Currently I use Process Explorer, find the pycharm entry, and watch for the new sub-processes after the notebook server starts. You want the leaf python.exe process, e.g:
6268 pycharm.exe
1235 python.exe (new when notebook launched)
7435 conhost.exe (new)
9237 python.exe (new - pick this PID)
I can now run a cell and hit the graphical breakpoints.
Enjoy.
On ubuntu i had to change the line kernel.yama.ptrace_scope = 1 in /etc/sysctl.d/10-ptrace.conf to kernel.yama.ptrace_scope = 0
otherwise pycharm was not able to attach to the ipython process.
Related
I initially started learning Python in Spyder, but decided to switch to PyCharm recently, hence I'm learning PyCharm with a Spyder-like mentality.
I'm interested in running a file in the Python console, but every time I rerun this file, it will run under a newly opened Python console. This can become annoying after a while, as there will be multiple Python consoles open which basically all do the same thing but with slight variations.
I would prefer to just have one single Python console and run an entire file within that single console. Would anybody know how to change this? Perhaps the mindset I'm using isn't very PyCharmic?
There is a specific option in PyCharm 2018.2+: Settings | Build, Execution, Deployment | Console | Use existing console for "Run with Python console".
Run with Python console is an option you have enabled in the Run Configuration. Disable it if you don't need a Python console after a script execution:
Hi: If you are looking for re running the code again in the same python console everytime then you have to check the respective box in the Project settings as shown in image below.
To allow only one instance to run, go to "Run" in the top bar, then "Edit Configurations...". Finally, check "Single instance only" at the right side. This will run only one instance and restart every time you run.
One console is one instance of Python being run on your system. If you want to run different variations of code within the same Python kernel, you can highlight the code you want to run and then choose the run option (Alt+Shift+F10 default).
You have an option to Rerun the program.
Simply open and navigate to currently running app with:
Alt+4 (Windows)
⌘+4 (Mac)
And then rerun it with:
Ctrl+R (Windows)
⌘+R (Mac)
Another option:
Show actions popup:
Ctrl+Shift+A (Windows)
⇧+⌘+A (Mac)
And type Rerun ..., IDE then hint you with desired action, and call it.
I think that what you are looking for is the last option in this window; check it and it should work.
Settings -> Build, Execution, Deployment -> Console
Python version : 3.6.1
Pycharm version : 2018.1 EAP (Professional Edition)
My python interpreter runs in interactive mode ON ITS OWN!!
I just ran the script
I ran the python script in PyCharm in the way that I usually did.
The interpreter had worked very well until the last night(2018/01/31) but...
But the interpreter has been changed like this
it has been changed in interactive mode AUTOMATICALLY.
I did just sleep, wake up and run it.
This is what actually I had seen
ran like this until the last night.
(I brought it from Google because I don't have a capture.)
PyCharm Preferences
But that doesn't mean that -i is in the interpreter option.
I got some solution that unchecking
"Show command line afterwards" box works, but I cannot find it.
import sys
print(sys.flags.interactive) # 0
Checked interactive flag is False.
It is kinda useful using interactive interpreter but I am now just uncomfortable for it.
How do I change it to uninteractive???
Go to Run > Edit configurations... menu. Select Python > your-script-name on the left and un-check the option Show command line afterwards on the right:
You'll find the option in Run > Edit Configurations
Is there a interface in Pycharm where we can simply type in some commands and run it ?
Something like in Matlab, we can type in "a = 1; b = 2; c = a+b" then we get ans=3.
Thanks
PS: we know we can create a python file in Pycharm and run it, e.g., "a = 1; b = 2; c = a+b; print(c)" but it is not as convenient as a command window.
Short answer from the docs:
To launch an interactive console
On the main menu, choose Tools | Run Python console.
Description:
REPL console
PyCharm also helps those who love the full control of an
interactive console: on the Tools menu, you can find commands that
launch the interactive Python or Django consoles. Here you can type
commands and execute them immediately. Moreover, PyCharm's interactive
consoles feature syntax highlighting, code completion, and allow
viewing the history of commands (Ctrl+Alt+E or Up/Down arrows while in
the editor).
PyCharm also makes it possible to run in console source code from the
editor — just make your selection, and then press Shift+Alt+E (Execute
selection in console on the context menu of the selection).
Independent of Pycharm, you can also access the REPL in the terminal (or cmd shell on Windows) by typing
python
at the prompt.
In PyCharm, you navigate to the View -> Tool Windows menu and toggle the Terminal window See image here. It will likely show up at the bottom of your IDE window.
Another very good (and more general option) is to use IDLE. From its Wikipedia entry...
IDLE is intended to be a simple IDE and suitable for beginners, especially in an educational environment. To that end, it is cross-platform, and avoids feature clutter.
It ships with basically every standard version of Python since 1.5.2 so I'm pretty sure you have it available on your system (I've checked with Linux and Mac OS X).
To fire up IDLE in Python2, enter: /path/to/python/bin/idle where /path/to/python/bin is where you find the Python executable.
For Python3, use idle3 instead.
You should see a new separate terminal window open up (with syntax highlighting and all!)See image here.
Find the attached screenshot..
You can observe the o/p of the editor in Run window.
You can also find Python Console and Command Terminal at the bottom of the Pycharm.
I have used standart ide for python - IDLE for a long time. It has convinient debug. I can write script, press F5 and it is possible to use all objects in terminal.
Now i want working with eclipse and pydev plugin. Is there any similar way to debug in eclipse?
Yes, there is.
Just start debugging - as far as I know, you have to set breakpoint, otherwise program just run to the end. And when stopped at breakpoint, in console window, click open console icon -> choose pydev console -> PyDev Debug Console.
Let me know if it works for you.
The PyDev debugger should be better to work with breakpoints and in a context... See: http://pydev.org/manual_101_run.html for basic instructions.
Note that when in a breakpoint you can simply issue commands in the console to print variables, etc.
Now, just for completeness, what IDLE has is closer to the PyDev interactive console: http://pydev.org/manual_adv_interactive_console.html Mostly, press Ctrl+Alt+Enter in your file and it'll execute the file in a buffer for you to work interactively.
I am running Pydev 2.7.3 with Eclipse 1.5. I'm trying to use the interactive console with the debugger (i.e. what I would like to do is insert a breakpoint in a file, run the file up to that breakpoint, then muck around with stuff in the interactive debugger). It seems like what I am trying to do fits this exactly: http://pydev.org/manual_adv_debug_console.html
But the interactive console does not DO anything. It prints "pydev debugger: starting", and any prints from before the breakpoint in my file, but when I try to type commands and execute them it is not responsive. It just advances one line and does nothing when I hit enter.
What's the deal? Or how can I start looking under the hood to figure out what is going on here?
EDIT
To be clear, I'm looking for the kind of functionality described here:
Jump into a Python Interactive Session mid-program?
Interactive console using Pydev in Eclipse?
but the "interactive" console that appears (as indicated in the answers to those questions) is not interactive.
EDIT: Problem seems to have resolved. No explanation other than restarting.