how to open an IPython console connected to an exiting running kernel in PyCharm - ipython

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.
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(), 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.

Related

Way to run python in VSCODE.dev

is there a way I can run python code in vscode .dev, im looking for a way to do this on a school Chromebook.
You can install the Python extension in VSCODE.dev, and then run the file with a Jupyter Server by right clicking and choosing "Run Current File in Interactive Window." HOWEVER: You must run the Jupyter Server on some computer (if you're chromebook has the Linux Development Environment enabled, you could do it there). You could run it on a remote computer, but that will cost money.

VSCODE terminal settings configuration

I am able to run streamlit and python on Anaconda cmd prompt on a separte window, but I can't get the streamlit to run on the VSCODE terminal (python runs fine). When I type in streamlit in the terminal, it generates a message saying
'streamlit' is not recognized as an internal or external command,
operable program or batch file.
I am guessing if I can get my VSCode terminal to run as Anaconda prompt, it should run streamlit without an error, as I am able to run streamlit on a separate Anaconda prompt outside of VSCode.
I am using Python 3.9.5 64-bit as my interpreter on VSCode and selected Command Prompt for my terminal option. I am on Windows environment.
I tried selecting Python 3.8.5 ('base') as my interpreter, but it threw the same message. Here is the image of the options I have for interpreter.
I had to create a new command prompt on VSCode that's using 3.8.5 ('base': conda) as my interpreter in order to successfully run streamlit!!

VSCode hangs when trying to run a Jupyter notebook?

I am trying to run a Jupyter notebook in VSCode. I have successfully run notebooks in the past, but something has happened to make VSCode "hang" when I try running. When I hit run, the terminal shows the file location and the location of python.exe as expected (shown in the first image, with some personal information redacted), but nothing ever happens. The code never completes and the cells never output. I get a small "pending" icon of a clock and an arrow (shown in the second image) to tell me a cell is running, but even the most basic "Hello, world" never completes or gives an error. I have no trouble running regular python files, and if I export an ipynb to py I can run it, but I cannot run the ipynb itself. Trying to restart the Jupyter kernel also seems to hang, never completing and never crashing or erroring. The only clue I really have is that when I hit F5 to run, there's no python version showing in the bottom left corner, the way there is when I run py files (third image is while trying to run ipynb and fourth image is while successfully running py).
I have tried uninstalling and reinstalling the Jupyter extension from VSCode and restarting VSCode between every step. I have tried swapping between python.exe and conda.exe in the terminal settings python.condapath. I have checked that the windows terminal is cmd. I've tried creating new notebooks in VSCode that only have print("Hello, world"). I have tried the command "Select interpreter to start Jupyter server" and selected the correct version of Python, but nothing has changed any time I've tried to run.
I am using Anaconda version 4.10.3, VSCode 1.61.2, IPython version 7.9.0, and Jupyter notebook version 6.4.3.

Setting up jupyter kernel in remote VSCode notebook

I am trying to run some notebooks in my virtual environment in the VSCode (remotely connected). I install the venv as usual via python3 -m venv <venv-name>, activate it and install all the needed modules. When I run which ipython I get the one from the venv so I install the kernel via ipython kernel install --name "<name>" --user and it is successfully created in ~/.local/share/jupyter/kernels/ directory and the kernel.json points to the venv python. Then I open the VSCode and select both the Python: Select Interpreter and Jupyter: Select Interpreter to start Jupyter server to point to the virtual environment's python, sth. like .../<venv-name>/bin/python3.
However, when I try to run the cell it wants me to select kernel (I can also do it myself in the upper right corner of the VSCode), but my newly created kernel is not there. There are only two (same) ones from usr/bin/python.
It is really strange since twice in two days my kernel magically appeared for one notebook and worked as desired, but when I opened a new notebook, my kernel was gone again. I tried to remove/reinstall kernels, venvs, VSCode's Python and Jupyter extensions but nothing helped. Any suggestions?
For now, I start the kernel in remote command-line via jupyter notebook --no-browser --ip=<ip> and then insert the connection link to Jupyter Server in the bottom right corner of the VSCode status bar but am wondering if there is an easier way since all the stuff (except VSCode) is on a remote machine?
This way is not easy. You can set up Jupyter Kernel easily.
Firstly, using ssh to connect to the remote server.
Secondly, open Command Palette (⇧⌘P) and enter Python: Select Interpreter, you can directly connecting to remote kernel.
resource: https://code.visualstudio.com/docs/datascience/jupyter-notebooks

Line number of edit window not showing in interactive window using Visual Studio and conda enviroment

I created a python project with Visual Studio, expecting to develop with conda and ipython, so I set the enviroment to Conda, and made sure to check the ipython within it...
I am expecting the following result, which has references to line numbers in the interactive window:
Turns out that i am getting this (without the line number):
What am I missing to achieve the desired result?
For this walkthrough you should have the Anaconda environment installed, which includes IPython and the necessary libraries:
Open Visual Studio, switch to the Python Environments window (View >
Other Windows > Python Environments), and select an Anaconda
environment.
Examine the Packages (Conda) tab (which may appear as pip or
Packages) for that environment to make sure that ipython and
matplotlib are listed. If not, install them here. (See Python
Environments windows - Packages tab.)
Select the Overview tab and select Use IPython interactive mode. (In
Visual Studio 2015, select Configure interactive options to open the
Options dialog, then set Interactive Mode to IPython, and select
OK).
Select Open interactive window to bring up the Interactive window in
IPython mode. You may need to reset the window if you have just
changed the interactive mode; you might also need to press Enter if
only a >>> prompt appears, so that you get a prompt like In [2].
https://learn.microsoft.com/en-us/visualstudio/python/tutorial-working-with-python-in-visual-studio-step-01-create-project?view=vs-2019