Issue
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.
Solution
(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.
- I have a project using a conda environment as its interpreter. Jupyter Notebook is installed in the conda environment.
- I open the Terminal tool window. It automatically activates the conda environment.
- I type
jupyter notebook
. The notebook server starts and a browser window opens. - I create a notebook in the browser, and execute a cell containing
foo = "bar"
. - In PyCharm, I open another Terminal tool window by clicking the plus sign to the left of the terminal pane.
- In the new terminal I type
jupyter console --existing
, and it starts an ipython console session. - At the prompt I type
dir()
, andfoo
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.
Answered By - jjpr
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.