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.
IPython is available on your computer with Anaconda. The corresponding Conda environment is set as the default interpreter for the current project. Once you set a Conda environment as a Python interpreter, PyCharm automatically recognizes IPython, and changes the prompt of the Python console. From the main menu, select Tools | Python Console.
You can assign a shortcut to open Python console: press Ctrl+Alt+S, navigate to Keymap, specify a shortcut for Main menu | Tools | Python or Debug Console. The main reason for using the Python console within PyCharm is to benefit from the main IDE features, such as code completion, code analysis, and quick fixes.
Once you set a Conda environment as a Python interpreter, PyCharm automatically recognizes IPython, and changes the prompt of the Python console. Use the magic commands of IPython From the main menu, select Tools | Python Console. If IPython has been properly installed, PyCharm will report about the version used.
Start a special IPython kernel, the IPython.kernel.inprocess.ipkernel.InProcessKernel, that allows a QtConsole in the same process. See examples/inprocess/embedded_qtconsole.py for an example.
(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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With