Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use IPython REPL in VS Code

Using the Python extension of Visual Studio Code, I can select some code, right-click it, and select "Run Selection/Line in Python Terminal" (alternatively, I can hit Shift+Enter). However, this sends the selected code to a plain old Python REPL in the Terminal pane, whereas I'd like to have this code run in IPython instead (not the QtConsole, just the terminal-based IPython).

Is it possible to set IPython as the default REPL? I tried setting /usr/local/bin/ipython3 as my default Python environment, but that doesn't work (it still executes the plain Python interpreter). FWIW, I'm on macOS.

like image 410
cbrnr Avatar asked Sep 13 '18 09:09

cbrnr


People also ask

How do I use REPL code in Visual Studio?

How to use. After installing this extension, bring up the command palette and paste a link to the repl (or the repl's uuid). You can open multiple repls in the same workspace. To use this, you will need to set your SID value, which is your session ID, this can be found by copying the value of the cookie named "connect.

Is IPython a REPL?

IPython is a powerful Python REPL that gives you tab completion, better tracebacks, multiline editing, and several useful features on top of pure Python Scripts. It is also the library that powers the Jupyter Kernel via the IPykernel.

Does Visual Studio code have a REPL?

JavaScript REPL is a javascript playground for Visual Studio Code with live feedback(logs or errors) as you type, besides your code, in a log explorer, or in an output channel. It supports Javascript, TypeScript, CoffeeScript and it can be used for development in Node.

How do I open REPL in Visual Studio?

By default, Visual Studio removes >>> and ... REPL prompts when pasting code from the Interactive window into the editor. You can change this behavior on the Tools > Options > Text Editor > Python > Advanced tab using the Paste removes REPL prompts option.


1 Answers

Adding the following setting (Preference: Open Settings JSON; or Preference -> Settings -> Search launchArgs -> edit in json) works without any extension. It also fixes the issue that multiple lines cannot be sent to Python.

"python.terminal.launchArgs": [     "-c",     "\"import subprocess; subprocess.call(['ipython', '--no-autoindent'])\"" ], 

Update (2020-12-27): the following setting seems to work better because it supports Ctrl+C keyboard interrupt without existing IPython:

"python.terminal.launchArgs": [     "-m",     "IPython",     "--no-autoindent", ], 
like image 53
Feng Mai Avatar answered Sep 19 '22 15:09

Feng Mai