01 - Welcome & Local Development Setup
Instructor and Course Overview
Welcome to Intermediate Python Programming for Research! This course is designed for researchers who have mastered the basics of Python and are ready to tackle more complex programming challenges. Whether you're building sophisticated data pipelines, developing custom analysis tools, or creating reusable research software, this course will elevate your Python skills to the next level.
As before, my name is Victor Gambarini. Having worked with Python for over a decade in both academic and production environments, I've seen firsthand how proper development practices can transform research workflows. This intermediate course builds on the foundation we established in the introductory course, but now we're moving beyond the training wheels of Colab into the professional world of local development.
Why Move to Local Development?
While Colab is excellent for learning and quick prototyping, serious Python development requires a more robust environment. In this course, you'll learn to work like professional developers and advanced researchers do - with full control over your environment, powerful debugging tools, and the ability to create complex, multi-file projects.
About This Course
Over the next five days, we'll transform you from a beginner Python user into a confident intermediate programmer. You'll learn industry-standard tools, best practices, and advanced techniques that will make your research code more reliable, maintainable, and powerful.
Course Structure
- Welcome & Local Development Setup - Professional Python environment with VS Code
- Virtual Environments & Package Management - Isolating and managing dependencies
- Advanced Data Structures & Algorithms - Beyond basic lists and loops
- Object-Oriented Programming for Research - Classes, inheritance, and design patterns
- Error Handling & Debugging - Writing robust, fault-tolerant code
- Advanced File Operations & APIs - Working with complex data sources
- Testing Your Research Code - Unit tests and validation frameworks
- Code Organization & Modules - Building reusable research libraries
- Performance Optimization - Making your code faster and more efficient
- Advanced Data Analysis Patterns - Complex pandas operations and data pipelines
- Creating Research Tools - Building command-line interfaces and utilities
- Documentation & Code Quality - Professional standards for research software
- Deployment & Sharing - Packaging and distributing your research tools
- Integration Project - Build a complete research application
- Advanced Resources - Pathways to expert-level development
What You'll Accomplish
By the end of this course, you'll be able to:
- Set up and manage professional Python development environments
- Write clean, maintainable, and well-tested research code
- Create complex, multi-file Python projects
- Debug and optimize your code effectively
- Build reusable tools and libraries for your research
- Follow software engineering best practices in research contexts
- Collaborate effectively on code projects with version control
Prerequisites
This course assumes you have completed the introductory Python course or have equivalent experience. You should be comfortable with:
- Basic Python syntax (variables, data types, functions)
- Working with lists, dictionaries, and basic data structures
- Using pandas for data manipulation
- Creating basic plots with matplotlib
- Understanding of loops and conditional statements
Why Use VS Code for Research
What is Visual Studio Code?
Visual Studio Code (VS Code) is a free, open-source code editor developed by Microsoft. It has become the most popular code editor among Python developers and researchers worldwide. Think of it as a supercharged text editor specifically designed for programming.
Why VS Code is Perfect for Research Programming
1. Powerful Code Intelligence
- Intelligent code completion and suggestions
- Real-time error detection and warnings
- Advanced debugging capabilities with breakpoints
- Integrated terminal for running commands
2. Extensive Python Support
- Official Python extension with rich features
- Jupyter notebook support within VS Code
- Interactive Python REPL
- Variable explorer and data viewer
3. Research-Friendly Features
- Git integration for version control
- Extension ecosystem for scientific computing
- Markdown preview for documentation
- LaTeX support for academic writing
4. Project Management
- Workspace management for complex projects
- File explorer with search capabilities
- Multi-file editing and navigation
- Integrated source control
5. Customization and Extensions
- Thousands of extensions for specialized tasks
- Customizable themes and layouts
- Snippet management for repetitive code
- Remote development capabilities
VS Code vs. Other Development Environments
Feature | VS Code | PyCharm | Spyder | Colab |
---|---|---|---|---|
Learning Curve | Easy | Steep | Moderate | Very Easy |
Performance | Fast | Heavy | Moderate | N/A |
Debugging | Excellent | Excellent | Good | Limited |
Extensions | Thousands | Many | Few | None |
Multi-language | Yes | Limited | No | Limited |
Cost | Free | Paid/Free | Free | Free |
Offline Work | Yes | Yes | Yes | No |
Installing Python Locally
Step 1: Download Python
For Windows: 1. Visit python.org/downloads 2. Download the latest Python 3.11 or 3.12 version 3. Important: Check "Add Python to PATH" during installation 4. Choose "Install Now" for standard installation
For macOS:
1. Visit python.org/downloads
2. Download the macOS installer
3. Run the installer and follow the prompts
4. Alternatively, use Homebrew: brew install python
For Linux (Ubuntu/Debian):
bash
sudo apt update
sudo apt install python3 python3-pip python3-venv
Step 2: Verify Installation
Open your terminal or command prompt and run:
bash
python --version
or
bash
python3 --version
You should see something like:
Python 3.12.0
Step 3: Install pip (if not included)
Pip is Python's package installer. Verify it's installed:
bash
pip --version
If not installed, download get-pip.py from bootstrap.pypa.io and run:
bash
python get-pip.py
Common Installation Issues
Windows PATH Problems: - If Python commands don't work, you may need to add Python to your PATH manually - Search for "Environment Variables" in Windows settings - Add Python installation directory to PATH
Permission Issues on macOS/Linux:
- Use python3
and pip3
instead of python
and pip
- May need to use sudo
for system-wide installations
Multiple Python Versions:
- Use python3.12
to specify exact version
- Consider using pyenv
for version management
Installing VS Code
Step 1: Download VS Code
- Visit code.visualstudio.com
- Download the installer for your operating system
- Run the installer and follow the setup wizard
Installation Tips: - Windows: Choose "Add to PATH" option - macOS: Drag VS Code to Applications folder - Linux: Use the provided .deb or .rpm package
Step 2: First Launch
- Open VS Code
- You'll see the Welcome tab with getting started information
- The interface consists of:
- Activity Bar (left): File explorer, search, source control, etc.
- Side Bar (center-left): Contents of selected activity
- Editor (center): Where you write code
- Terminal (bottom): Command line interface
Step 3: Essential Settings
Enable Auto Save:
1. Go to File > Preferences > Settings (or Ctrl + ,
)
2. Search for "auto save"
3. Set Auto Save to "afterDelay"
Configure Terminal: 1. View > Terminal (or `Ctrl + ``) 2. Ensure it opens to your preferred shell
Installing Python Extension
Step 1: Open Extensions View
- Click the Extensions icon in the Activity Bar (or press
Ctrl + Shift + X
) - Search for "Python"
- Look for the official "Python" extension by Microsoft
Step 2: Install the Extension
- Click "Install" on the Python extension
- VS Code will download and install the extension
- You may need to reload VS Code when prompted
Step 3: Configure Python Interpreter
- Open the Command Palette (
Ctrl + Shift + P
) - Type "Python: Select Interpreter"
- Choose your installed Python version from the list
- VS Code will remember this setting for future sessions
Additional Useful Extensions
For Research and Data Science:
- Jupyter - Notebook support in VS Code
- Search for "Jupyter" and install the official extension
-
Enables .ipynb file support
-
Python Docstring Generator - Auto-generate documentation
-
Helps write proper function documentation
-
GitLens - Enhanced Git capabilities
-
Advanced version control features
-
Markdown All in One - Better markdown support
-
For writing documentation and README files
-
Python Type Hint - Better type checking
- Helps catch errors before runtime
Verifying Extension Installation
- Create a new file: File > New File
- Save it as
test.py
- Type some Python code:
print("Hello, VS Code!")
x = [1, 2, 3, 4, 5]
print(sum(x))
- You should see:
- Syntax highlighting (colored code)
- Code completion suggestions
- A "Run Python File" button in the top-right corner
Your First Local Python Script
Step 1: Create a Project Folder
- Create a new folder on your computer called
intermediate-python-course
- In VS Code, go to File > Open Folder
- Select your new folder
- VS Code will open with your folder in the Explorer
Step 2: Create Your First Script
- Right-click in the Explorer panel
- Select "New File"
- Name it
hello_research.py
- Add the following code:
!/usr/bin/env python3
"""
My first local Python script for research
This script demonstrates basic Python setup verification
"""
import sys
import platform
from datetime import datetime
def system_info():
"""Display system and Python information"""
print("=" * 50)
print("RESEARCH PYTHON ENVIRONMENT INFO")
print("=" * 50)
print(f"Python Version: {sys.version}")
print(f"Platform: {platform.system()} {platform.release()}")
print(f"Current Time: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
print(f"Script Location: {__file__}")
print("\nPython Path:")
for path in sys.path[:3]: # Show first 3 paths
print(f" - {path}")
print("\nInstalled Packages Check:")
required_packages = ['pandas', 'numpy', 'matplotlib', 'seaborn']
for package in required_packages:
try:
__import__(package)
print(f" ✓ {package} - Available")
except ImportError:
print(f" ✗ {package} - Not installed")
print("=" * 50)
if name == "main":
print("Welcome to Intermediate Python for Research!")
print("This script verifies your local development setup.\n")
system_info()
print("\nIf you see this message, your Python environment is working!")
print("You're ready to start building serious research tools! 🚀")
Step 3: Run Your Script
Method 1: Using VS Code's Run Button 1. Click the "Run Python File" triangle button in the top-right 2. Output will appear in the Terminal panel below
Method 2: Using the Terminal
1. Open the integrated terminal: View > Terminal
2. Type: python hello_research.py
3. Press Enter
Method 3: Using Command Palette
1. Press Ctrl + Shift + P
2. Type "Python: Run Python File in Terminal"
3. Press Enter
Step 4: Understanding the Output
Your script should display: - Python version information - Operating system details - Current timestamp - Available packages status
If any required packages are missing, don't worry - we'll install them in the next session!
Essential VS Code Features for Research
1. Integrated Terminal
The integrated terminal is one of VS Code's most powerful features:
- Open Terminal: View > Terminal or
Ctrl + `
- Multiple Terminals: Click the + icon to create new terminals
- Terminal Types: PowerShell, Command Prompt, Git Bash (Windows), or Bash/Zsh (macOS/Linux)
2. File Explorer and Search
- Explorer Panel: View files and folders in your project
- Quick Open:
Ctrl + P
to quickly open files by name - Search Across Files:
Ctrl + Shift + F
to search all files in your project
3. IntelliSense and Code Completion
- Auto-completion: Type and press
Tab
to accept suggestions - Parameter Hints: See function parameters as you type
- Quick Documentation: Hover over functions to see documentation
4. Debugging
- Set Breakpoints: Click in the gutter next to line numbers
- Start Debugging: F5 or Run > Start Debugging
- Variable Inspection: View variable values while debugging
- Call Stack: See the execution path
5. Git Integration
- Source Control Panel: View > Source Control
- Stage Changes: Click + next to modified files
- Commit: Add message and commit changes
- Push/Pull: Sync with remote repositories
6. Command Palette
The Command Palette (Ctrl + Shift + P
) gives you access to all VS Code features:
- Python: Run Python File in Terminal
- Python: Select Interpreter
- Format Document
- Git: Clone
- File: New File
7. Workspace Settings
Create project-specific settings:
- Create a
.vscode
folder in your project - Add a
settings.json
file:
json
{
"python.defaultInterpreterPath": "./venv/bin/python",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.provider": "black",
"files.autoSave": "afterDelay",
"files.autoSaveDelay": 1000
}
Quick Reference
Essential Keyboard Shortcuts
Ctrl + Shift + P
: Command PaletteCtrl + P
: Quick File OpenF5
: Start Debugging- `Ctrl + ``: Toggle Terminal
Ctrl + /
: Toggle Line CommentShift + Alt + F
: Format DocumentCtrl + Shift + X
: Extensions ViewCtrl + Shift + G
: Source ControlF12
: Go to DefinitionCtrl + Space
: Trigger IntelliSense
Python-Specific Shortcuts
Shift + Enter
: Run Selected Lines in TerminalCtrl + F5
: Run Without DebuggingF9
: Toggle BreakpointF10
: Step Over (debugging)F11
: Step Into (debugging)
File Operations
Ctrl + N
: New FileCtrl + S
: Save FileCtrl + Shift + S
: Save AsCtrl + O
: Open FileCtrl + K, Ctrl + O
: Open Folder
Getting Help in VS Code
- Help > Welcome: Getting started guide
- Help > Interactive Editor Playground: Learn VS Code features
- Command Palette > "Help": Access various help options
- F1: Alternative to Command Palette
Troubleshooting Common Issues
Python Not Found:
- Check if Python is in PATH
- Use Command Palette: "Python: Select Interpreter"
- Verify installation with python --version
in terminal
Extensions Not Working: - Reload VS Code: Command Palette > "Developer: Reload Window" - Check extension is enabled in Extensions view - Look for error messages in Output panel
Terminal Issues: - Try different terminal type (PowerShell vs Command Prompt) - Check default terminal setting in preferences - Restart VS Code if terminal becomes unresponsive
What's Next?
In our next session, we'll dive into virtual environments and package management - crucial skills for managing complex research projects. You'll learn how to:
- Create isolated Python environments for different projects
- Install and manage packages with pip and conda
- Handle dependency conflicts
- Set up reproducible research environments
Make sure you can comfortably create Python files, run scripts, and navigate VS Code before we continue. The skills you've learned today form the foundation for everything we'll build in this intermediate course.
Homework
Before the next session:
- Practice with VS Code: Create a few Python files and get comfortable with the interface
- Explore Extensions: Browse the Extensions marketplace and install any that look useful
- Try the debugger: Set a breakpoint in your script and step through the code
- Check package installations: Note which packages are missing from the system check script
Remember: the transition from Colab to local development might feel overwhelming at first, but the power and flexibility you gain will transform your research workflow. You're now working with the same tools used by professional developers and advanced researchers worldwide!
Enjoying this course?
This is just the first episode! Register to unlock 0 more episodes and complete your learning journey.
Register for Full Course