If you have a default vanilla installation of the Python extension in VSCode, by default you can highlight python code and do "SHIFT+ENTER" to "Run Selection/Line in Python Terminal".
That command will use the default python.exe interpreter. However, this is the trick that works for me to use the IPython shell instead.
- First run a dummy line of python code by highlighting it and doing SHIFT+ENTER. This launches a terminal named "python" and starts the python shell to run the code in the REPL.
- Now issue
exit() in that python shell to return to the regular terminal prompt.
- Run
ipython in that terminal to start the IPython REPL where the plain old Python REPL used to be.
Now subsequent uses of SHIFT+ENTER (single or multiple lines highlighted) will run the code in the IPython shell.
(Note, if SHIFT+ENTER is sending code to the Python Interactive split window instead of a terminal REPL, make sure your settings.json has "jupyter.sendSelectionToInteractiveWindow": false,)
[EDIT]. Various comments on this thread remark that using the various solutions, code is copied to the IPython terminal, but not run. I realized I also have this experience depending on my active conda environment. If I do conda install -c conda-forge prompt-toolkit in the environment I'm using, I get the expected behavior where SHIFT+ENTER actually runs code. I don't know if that package is the key, one of its dependencies, or just using conda-forge. But it works!
code runnerextension as well.