2

I've recently switched to VSCode, and am wondering if there's a way to make the Python Interactive Window from the Jupyter support in VSCode work like the console in Spyder where I just have to select code and press ctrl+enter to send it, without having to create cells everytime.

For now I'm resigned to work with the Terminal until my code is clean and then create a cell when I have reusable code, and would like to just work directly with the PIW.

6 Answers 6

4

You can always change the default console setting by:

  • Opening the Command Palette (⇧⌘P)
  • Typing "Preferences:Open Settings (JSON)
  • Edit this line:

    "python.dataScience.sendSelectionToInteractiveWindow": false
    
Sign up to request clarification or add additional context in comments.

Comments

1

You should be able to do this with the latest python extension. The select the code you want to execute and press shift-enter. Is that not working?

3 Comments

No. If I select code with no Jupyter cells in the file and press ctrl + enter, VSCode creates a Python terminal and sends the code there :|
I was wondering if there was a way to configure VSCode so that every ctrl + enter command goes directly to the Python Interactive Window from the Jupyter support.
Sorry, I meant shift + enter
1

For me (now) interactive mode runs after setting "jupyter.sendSelectionToInteractiveWindow": true

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
0

@FranciscoRZ. You should have seen a popup option for this, but if it didn't come up for you it can just be manually set in VSCode options. Just change this guy here:

Python->Data Science: Send Selection To Interactive Window

That should get you what you are looking for.

OP's Note: Accepting this answer because it will be the right anwser starting with the February release of VS Code Python

3 Comments

thanks for taking an interest in this. Unfortunately I can't find the setting you're speaking of, and I still do not get the pop-up when pressing shift+enter. Is there a mismatch between the Anaconda distribution of VSCode and the latest Microsoft distribution?
Here is the list of my VSCode settings when I search for Data Science which seemed like they might be relevant: Allow Import From Notebook (True), Allow Input (True),Change Dir On Import Export (True), Code Regular Expression (default), Data Science Enabled (True), Export With Output Enabled (False), Jupyter Server URI (local), Notebook File Root (${workspaceFolder}), Search For Jupyter (True), Show Cell Input Code (True), Use Default Config for Jupyter (True). They are all at default values - I wonder if there's some set up to do for them to work from within a Conda env.
Sorry (mentioned this on GitHub as well) but this feature is actually just in our development build currently. You'll need to wait for the Feb. release or try our development build here: github.com/Microsoft/vscode-python/blob/master/… My apologies for not mentioning that on my initial post
0

If you have the notebook saved as a python percentage script (which is more git friendly) each "cell" will be delimited by # %% and the default run command is "Shift+Ctrl". Later once you are working in the interactive window, If you want a particular cell you wrote on the fly to be in you script, there is one button which says "Paste code into file" right next to the recently executed cell in the interactive window. And in case you are using the notebook for the sake of being able to later export it to html or pdf, once executed in the interactive window, there is an export button as well.

Comments

0

for me what worked is this:

  1. Ctrl + Shift + P
  2. type in "settings.json"
  3. Click "Preferences: Open User Settings (JSON)
  4. in there (it was empty) I copied the following line:
{
    "jupyter.interactiveWindow.textEditor.executeSelection.": true
}

I think this is the updated version of the line

"python.dataScience.sendSelectionToInteractiveWindow": false

Hope this works for you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.