A VS Code extension that allows you to execute Python cells in an IPython terminal with shared namespace between cells.
- Execute Python cells (delimited by
#%%) in an IPython terminal - Shared namespace between cells and the IPython terminal (variables and imports persist)
- Line-by-line execution for selections (perfect for debugging sessions)
- Automatically creates an IPython terminal if none exists
- Returns focus to the editor after execution
- Supports both regular development and debugging workflows
- VS Code 1.74.0 or higher
- IPython must be installed in your Python environment
This extension is available on the VS Code Marketplace here.
- Download the
.vsixfile - Open VS Code
- Go to Extensions view (Ctrl+Shift+X)
- Click the "..." menu at the top of the Extensions view
- Select "Install from VSIX..."
- Navigate to and select the
.vsixfile
- Clone this repository
- Run
npm installto install dependencies - Run
npm run compileto build the extension - Package the extension:
vsce package --allow-missing-repository --skip-license - Install the resulting
.vsixfile in VS Code using "Install from VSIX..."
Ctrl+Alt+Enter: Execute the current cell in the IPython terminalCtrl+Shift+Enter: Execute the current selection in the IPython terminal (line-by-line)
You can also use the Command Palette (Ctrl+Shift+P) to run the following commands:
IPython: Execute Current Cell in TerminalIPython: Execute Current Selection in Terminal
When you execute a cell:
- The extension identifies the cell containing your cursor (delimited by
#%%) - It removes the cell delimiter line if present
- It copies the code to the clipboard
- It uses IPython's
%paste -qmagic to execute the code in the active namespace - Focus returns to the editor
When you execute a selection:
- The extension sends each line of your selected code individually to the IPython terminal
- This works even when you're at a PDB or IPDB prompt
- Focus returns to the editor after execution
When debugging with PDB or IPDB, you can toggle "PDB Mode" to improve how code is executed:
- Use
Ctrl+Alt+,to toggle between regular IPython mode and PDB mode - In PDB mode, the extension uses specialized line-by-line execution that preserves variable scope and state
- A status bar indicator shows whether you're in "IPython Mode" or "PDB Mode"
When in PDB mode, selection execution (Ctrl+Shift+Enter) has smart behavior:
- For single-line expressions (e.g., variable names), it sends the expression directly to the terminal
- This allows you to see the values of variables by simply selecting and executing them
- For multi-line code or statements with control structures, it uses a specialized line-by-line execution
- This preserves your PDB session state and allows complex code blocks to execute properly
- Variables defined in executed code blocks will be available in your PDB session
The extension automatically handles indented code blocks:
- When executing code in PDB mode, the extension normalizes indentation before sending it line-by-line
- This means you can select and execute code that's indented within functions or classes
- The extension also handles line continuations (backslash at the end of a line)
- These formatting improvements ensure your code executes correctly within the PDB session
- Execute cells with
Ctrl+Alt+Enterduring normal development - When you hit a breakpoint (using
pdb.set_trace(),breakpoint(), etc.), switch to PDB mode withCtrl+Alt+, - Use the selection execution method that fits your current need:
- Select a variable name and press
Ctrl+Shift+Enterto see its value - Select a multi-line code block and press
Ctrl+Shift+Enterto execute it with proper indentation
- Select a variable name and press
- When you exit PDB, switch back to regular mode with
Ctrl+Alt+, - All variables defined during PDB mode execution will be available in your debugging session
You can customize the extension's keyboard shortcuts through VS Code's keyboard shortcuts editor:
- Open VS Code's keyboard shortcuts (File > Preferences > Keyboard Shortcuts)
- Search for "ipython" to find and modify the extension's commands
If the extension can't find your IPython terminal:
- Open a new terminal in VS Code
- Run
ipython - Try executing your cell again
Make sure:
- Your cursor is inside a Python cell
- IPython is properly installed in your environment
- Your code doesn't contain syntax errors
To publish a new version of this extension:
-
Update the version in
package.json:"version": "0.2.8"
Follow semantic versioning: MAJOR.MINOR.PATCH
-
Compile the extension:
npm run compile
-
Publish to the marketplace:
vsce publish -p YOUR_PERSONAL_ACCESS_TOKEN
About the Personal Access Token (PAT)
- The PAT is required for every publish operation (not just the initial one)
- Get your PAT from Azure DevOps: https://dev.azure.com
- The PAT must have Marketplace (Manage) scope
Publisher account
- Publisher:
agentmorris - Manage extensions at: https://marketplace.visualstudio.com/manage/publishers/agentmorris