how to open an IPython console connected to an exiting running kernel in PyCharm
Is there a way to open an IPython interactive console in pycharm that is connected to an existing running kernel (similar to "python --existing")?
btw: in case it's relevant, in my case, the running kernel is of a Jupiter notebook...
EDIT: To clarify, my question is NOT about how to open an interactive console in PyCharm. It is about how to connect that interactive console to a an existing running (Jupiter notebook) Kernel.
( tl;dr : Use jupyter console --existing
in the PyCharm "Terminal" tool window (not the "Python Console" tool window) to connect to an existing iPython kernel running in a local Jupyter Notebook server.)
I can confirm that the comment by @john-moutafis suggesting ipython console --existing
is the right idea. The command gives "WARNING | You likely want to use jupyter console
in the future" so I tried that.
jupyter notebook
. The notebook server starts and a browser window opens. foo = "bar"
. jupyter console --existing
, and it starts an ipython console session. dir()
, and foo
is among the results, confirming that I'm attached to the same kernel as the notebook. I don't know how it picks which kernel to connect to when there are multiple kernels running in the notebook server.
Don't type exit
in the iPython session if you plan to continue using the notebook, it shuts down the kernel.
Unfortunately, tools like Debug and "Execute Line/Selection in Console", which are available for the "Python Console" tool window, are not available for the "Terminal" tool window. In fact, because the Terminal tool window is a simple tool, and that's where I've run my commands, this solution isn't very integrated with PyCharm. The terminal opens in the project directory and activates the conda environment, and it's conveniently adjacent to the editors and tools of the IDE, but otherwise there's no connection to PyCharm's tools.
If anyone can successfully attach PyCharm's integrated PyDev debugger to a running kernel, please chime in.
I'm using PyCharm 2016.3 on macOS 10.12.3.
The easiest way for me is just to type %qtconsole in a jupyter notebook cell and run it. A qt console will open already connected to the running kennel. No PyCharm involved.
链接地址: http://www.djcxy.com/p/38630.html