Home

Python Coding in VS Code

You want to write Python code but aren’t sure which editor to use, or you’re looking for something lighter than PyCharm. Think of VS Code as a Swiss Army knife - it handles Python, R, JavaScript, and many other languages in one lightweight editor. This tutorial shows you how to set up Python in VS Code with smart features like code completion, interactive debugging, and even web apps.

Key Concepts

What You’ll Need

Step 1: Install Python

You need Python 3.8 or higher for the best compatibility with modern packages.

Verify installation by opening a terminal and typing python3 --version or python --version.

Step 2: Install Python Extensions in VS Code

The Python extension includes support for debugging, IntelliSense, code formatting, and Jupyter notebooks.

Step 3: Create Your Python Project

Step 4: Select Python Interpreter

VS Code needs to know which Python installation to use.

If you don’t see your Python installation, click Enter interpreter path and navigate to where Python is installed.

Step 5: Create a Virtual Environment

Virtual environments keep your project dependencies isolated.

You’ll see (.venv) in your terminal prompt when the environment is active.

Step 6: Install Required Packages

pip install pandas matplotlib streamlit

If (.venv) doesn’t appear, the environment isn’t active. Click View > Command Palette, run Python: Select Interpreter, then choose the interpreter with ('.venv': venv) next to it.

Step 7: Write Your First Python Script

Type this code into analysis.py:

import pandas as pd
import matplotlib.pyplot as plt

# Load the iris dataset
url = "https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv"
iris = pd.read_csv(url)

# View the first few rows
print(iris.head())

# Generate summary statistics
print("\nSummary Statistics:")
print(iris.describe())

# Create a histogram
plt.figure(figsize=(8, 6))
plt.hist(iris['sepal_length'], bins=20, color='steelblue', edgecolor='white')
plt.xlabel('Sepal Length (cm)')
plt.ylabel('Frequency')
plt.title('Distribution of Sepal Length')
plt.show()

Step 8: Run Python Code Interactively

Step 9: Create a Simple Streamlit App

import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt

st.title("Interactive Histogram")

# Sidebar slider
bins = st.sidebar.slider(
    "Number of bins:",
    min_value=5,
    max_value=50,
    value=30
)

# Load data
url = "https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv"
iris = pd.read_csv(url)

# Create histogram
fig, ax = plt.subplots(figsize=(8, 6))
ax.hist(iris['sepal_length'], bins=bins, color='steelblue', edgecolor='white')
ax.set_xlabel('Sepal Length (cm)')
ax.set_ylabel('Frequency')
ax.set_title('Distribution of Sepal Length')

# Display in Streamlit
st.pyplot(fig)
streamlit run app.py

Step 10: Use Code Completion and IntelliSense

Step 11: Try Debugging

Next Steps

Troubleshooting

Workflow Summary

VS Code provides a modern, lightweight environment for Python development with these advantages:


Created by Steven Ge on December 7, 2025.