DEV Community

Pavol Z. Kutaj
Pavol Z. Kutaj

Posted on

How to use iPython in VS Code

The aim of this page πŸ“ is to explain how to use IPython as the default Python REPL (watch Sebastian Witowski's talk if not convinced) and configure VS Code to execute code in IPython, as I am slowly switching to iPython for my default REPL. A big part of this is to be able to execute selections of code with shift+enter in VS Code, and then quickly toggle between ipython for exploration, and vscode for code editting. I was toying with an idea to create a pure-vim workflow, but the combination of VS Code + iPython set up this fast is too tempting.

  • Configure VS Code to use IPython with Shift+Enter: Open settings (Ctrl+, or Cmd+,), and add/update in settings.json:
python.terminal.launchArgs": [ "-m", "IPython", "--no-autoindent", ], 
Enter fullscreen mode Exit fullscreen mode
  • Example issue when running IPython:
 /opt/homebrew/opt/python@3.13/bin/python3.13: No module named ipython 
Enter fullscreen mode Exit fullscreen mode
  • Resolve by installing IPython in correct environment:
 python -m pip install ipython 
Enter fullscreen mode Exit fullscreen mode
  • I am using shift+alt+p for quick toggling between iPython in a terminal panel and VS Code proper. This is the keyboard shortcut config
 { "key": "shift+alt+p", "command": "workbench.action.focusPanel", "when": "!panelFocus" }, { "key": "shift+alt+p", "command": "workbench.action.focusActiveEditorGroup", "when": "panelFocus" } 
Enter fullscreen mode Exit fullscreen mode

LINKS

Top comments (0)