TransWikia.com

VS Code: Shift+Enter does not send code to Python Interactive - why?

Super User Asked on December 9, 2020

I’m currently setting up a python development environment with Anaconda and VS Code.

On my old laptop, I could run python code by pressing Shift+Enter and VS Code would send it to the Python Interactive window. When I do this now, the code gets sent to the Terminal. Shift+Enter is registered as a keyboard shortcut for both sending code to Terminal and for sending it to Python Interactive.

I can run stuff in Python Interactive by right clicking and selecting "Run current file in python interactive window".

What I want is that the selected code is run in Python Interactive by pressing Shift+Enter.

How do I do this?

4 Answers

I was struggling with the same problem, and finally have found out that it's related to the global settings.

If you go to the Settings( Ctrl + , ) you can see the search bar. There, put in 'Send Selection To Interactive Window' or the like, and click the checkbox of 'Python › Data Science: Send Selection To Interactive Window'. After that, you would be able to run certain lines directly in the Interactive Window.

Hope this could help you. :)

Correct answer by sam7351 on December 9, 2020

Press CtrlShift+P

Type in "Preferences: Open Settings (JSON)"

Paste this in the JSON file:

"python.dataScience.sendSelectionToInteractiveWindow": true

and save.

Answered by A Merii on December 9, 2020

In my case (VS Code 1.47.2), the shortcuts Run Selection in Python Terminal and Run Selection in Python Interactive Windows are in conflict with each other (probably messed up by myself a while ago).

The resolution is straightforward: Go to

File -> Preferences -> Keyboard Shortcuts -> Type run selection.

In the result list, change the keybinding of the shortcuts Run .. in Terminal, Run .. in Interactive Windows and Run Cell to Shift+Enter, Alt+Enter and Ctrl+Enter, respectively, or whatever you like as long as no more conflict shows.

Alternatively, you can also look for all shortcuts with the shift+enter keybiding: Go to

File -> Preferences -> Keyboard Shortcuts -> Type "Shift+Enter".

In the result list, change or delete (right click -> remove keybinding or Delete) the keybinding of the shortcuts that also the same keybinding.

Answered by Li-Pin Juan on December 9, 2020

same issue here. Shift+Enter was working just fine. I was getting an error that I tried to fix, and since then, the "right click" menu has changed.

When I select code and choose right click,Run File in Python Interactive Window, it works. But when I press shift+enter, I get all kinds of errors.

The error I got initially was "This Python interpreter is in a conda environment, but the environment has not been activated. Libraries may fail to load. To activate this environment please see https://conda.io/activation". Trying to fix it has led to the current state....I'll have toe re-trace my steps to see what went wrong.

Have you had any success yet? Thanks!

Answered by Chet on December 9, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP