Dan
Dan

Reputation: 1175

Connect to existing kernel in VS Code

With the recent sunsetting of Atom, I am migrating to VS Code for exploratory analysis of scientific data.

Currently in VS Code, I am able to run my Python files (not Jupyter notebooks) in cell mode by starting a local iPython for each .py file. This works fine and reproduces a subset of the functionality I had with Atom/Hydrogen.

However, with Atom/Hydrogen, I could connect multiple .py files to a single kernel. To do this I would start Python in one file. Then I would switch to another file and bring up the Atom command palette and select "Hydrogen: Connect to Existing Kernel". After that both files shared the same kernel, workspace, variables, etc.

I have not been able to reproduce this functionality in VS Code. There is guidance on how to connect to existing Jupyter kernels using Jupyter Notebooks in VS Code, but the steps there do not work for me when using .py files. There is another question on SO that seems to describe a similar problem but, again, it's notebook-specific.

How can I connect multiple .py files to a single kernel in VS Code?

Upvotes: 0

Views: 1440

Answers (1)

MingJie-MSFT
MingJie-MSFT

Reputation: 9229

I code two files.

test1.py

x=1

test2.py

print(x)

Obviously, when I run them alone in the interactive window, test2 will make an error. It cannot find the defined x.

However, search Jupyter: Interactive Windows Mode in settings and change it to multiple.

They can work in the same kernel. Hope this can help.

enter image description here

enter image description here

Upvotes: 1

Related Questions