0

This seems like a basic question, but I can't seem to find a setting/process for it.

In VSCode's Python extension, there is an option to right-click (or keyboard shortcut) in the editor and Run Current File in Python Interactive Window. This works great.

Is there a way to Run Main File in Python Interactive Window so to speak? If you are building a package/module and are making changing in a non-main file, you currently need to switch back to that main file editor tab before running it as described above.

It would be nice to link module/package files to run the main file from anywhere in the package and not have to switch files in the editor. This would make building/debugging a separate module file much faster using the Python Interactive Window. Thanks

Gama11
  • 31,714
  • 9
  • 78
  • 100
secJ
  • 499
  • 3
  • 12

2 Answers2

0

Create a launch option that names the main python file instead of the current file and choose it in the debug/run sidebar.

You might need to set the cwd property to the correct value.

Now when you press F5 the main python file is run.

rioV8
  • 24,506
  • 3
  • 32
  • 49
  • 1
    that may work. I don't know what the parameters would be for this config, so will have to dig around (unless you know what they might be?) – secJ Jul 17 '20 at 19:39
  • @secJ Read the debug doc for VSC, it explains the format of `launch.json` – rioV8 Jul 17 '20 at 20:42
  • Thanks again. I found it, but unfortunately this isn't quite what I'm looking for. I'd like to simply run the package code in the `Python Interactive Window` (i.e. Jupyter notebook) when I press `command + enter` (or right-click in the editor). I don't want to run the actual debugger. I'm guessing this may be a limitation of the python extension? It seems to be calling `python.datascience.runFileInteractive`. Ideally I could setup an alternate shortcut to specify the actual file that is run – secJ Jul 18 '20 at 18:41
0

Try searching for the Jupyter extension in your IDE. Note: When you try to run it the first time it will want to install the Jupyter kernal

Publisher: Microsoft Jupyter

Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter

Now available to run from drop down options on run button. following pic is VS Code.

enter image description here

ned
  • 1
  • 1