The best of both worlds
Interactive Python mode is my favorite way to write Python code, and I rarely use anything else. It combines the organization of Python files with the interactivity of Jupyter notebooks.This is how I’ll be coding throughout the entire course. Once you try it, you’ll understand why it’s so powerful for learning and developing AI applications.
What is Interactive Python?
Imagine you’re cooking and tasting as you go, rather than waiting until the entire meal is done. That’s Interactive Python:- Write code in a
.pyfile (organized and clean) - Run pieces of it instantly with
Shift + Enter - See results immediately in a side panel
- Keep all your variables in memory
Why it’s perfect for AI development
When working with AI and data:- You’re constantly inspecting data
- Testing transformations
- Checking outputs
- Experimenting with different approaches
hello.py) would be slow and frustrating. Interactive mode lets you work iteratively.
Prerequisites
Interactive Python requires the IPython kernel. Let’s install it:-
Make sure your virtual environment is activated:
-
Install the required package:
Set up Interactive Python
Now let’s enable the interactive feature:-
Open VS Code settings:
- Press
Ctrl/Cmd + ,(comma) - Or File > Preferences > Settings
- Press
- Search for “execute selection”
- Find this setting: Jupyter > Interactive Window > Text Editor: Execute Selection
- Check the box to enable it
Shift + Enter, your selected code will run in the Jupyter interactive window instead of the Python terminal. This gives you a much richer, more visual experience.
That’s it! You’re ready to use interactive mode.
Your first interactive session
-
Create a new file called
interactive_demo.py - Type this code:
- Place your cursor on the first line
-
Press
Shift + Enter
- An Interactive window opens on the right
- Your code runs line by line
- You see output immediately
Interactive superpowers
Run selected code
- Highlight any code
- Press
Shift + Enter - Only that selection runs
Variables stay in memory
Run this step by step:message stays available throughout your session!
Start learning Python
Your environment is perfect. Let’s dive into Python fundamentals!