Skip to main content
Advertisement

Ch 1.3 Setting Up Your Development Environment

Now that the Python interpreter is installed, it is time to configure a development environment for writing code efficiently. Let's build an environment ready for professional use — from editor configuration to code quality tools.

1. VS Code Configuration

Visual Studio Code is a lightweight, highly extensible editor that is the most popular choice for Python development.

Installing Essential Extensions

  1. Download VS Code
  2. Install from the Extensions tab:
    • Python (Microsoft) — Core Python support
    • Pylance (Microsoft) — High-speed language server, type checking
    • Ruff — Fast linter/formatter
    • Python Debugger (Microsoft) — Debugging support

Selecting the Python Interpreter

Ctrl+Shift+P (macOS: Cmd+Shift+P)
→ "Python: Select Interpreter"
→ Choose the desired Python version or virtual environment

Example settings.json Configuration

Create or edit the .vscode/settings.json file:

{
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
"editor.formatOnSave": true,
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.ruff": "explicit",
"source.organizeImports.ruff": "explicit"
}
},
"python.analysis.typeCheckingMode": "basic",
"python.analysis.autoImportCompletions": true,
"editor.rulers": [88],
"files.trimTrailingWhitespace": true
}

2. PyCharm Configuration

PyCharm is a dedicated Python IDE from JetBrains that offers a rich set of features.

Community vs Professional

Community (Free)Professional (Paid)
Basic Python support
Debugger
Virtual environment management
Web framework support✅ (Django, FastAPI)
Database tools
Remote development
Jupyter integration

For learning: The Community edition is sufficient.

Setting the Interpreter

File → Settings (macOS: PyCharm → Preferences)
→ Project: [Project Name]
→ Python Interpreter
→ Add Interpreter → Virtualenv Environment

3. Jupyter Notebook / Lab

Jupyter is an interactive environment for writing code, text, and visualizations all in a single document. It is especially well-suited for data analysis and education.

Installation and Launch

# Install after activating a virtual environment
pip install jupyter notebook jupyterlab

# Launch Jupyter Notebook
jupyter notebook

# Launch JupyterLab (more modern UI)
jupyter lab

Basic Usage

# Run a cell: Shift+Enter (move to next cell), Ctrl+Enter (stay in current cell)
# Add a new cell: A (above), B (below)
# Delete a cell: DD

# Code cell example
import pandas as pd
import matplotlib.pyplot as plt

data = {"Name": ["Alice", "Bob", "Charlie"], "Score": [95, 87, 92]}
df = pd.DataFrame(data)
print(df)

Installing ipykernel (virtual environment integration)

# After activating your virtual environment
pip install ipykernel

# Register the virtual environment as a Jupyter kernel
python -m ipykernel install --user --name=my-project --display-name "My Project (Python 3.12)"

# List registered kernels
jupyter kernelspec list

Using Markdown Cells

Switching a cell type to Markdown lets you write formulas, text, and tables.

# Title
## Math Support
$E = mc^2$

| Column1 | Column2 |
|---------|---------|
| Value1 | Value2 |

4. Using the Python REPL

REPL (Read-Eval-Print Loop) is an interactive environment for running code and seeing results immediately.

Basic Python REPL

# Launch the REPL
python3

# Exit
exit() or Ctrl+D
# Experiment immediately in the REPL
>>> 2 + 3
5
>>> "hello".upper()
'HELLO'
>>> [x**2 for x in range(5)]
[0, 1, 4, 9, 16]

# The last result is stored in the _ variable
>>> 10 * 5
50
>>> _ + 1
51
>>> _ * 2
102

IPython (Enhanced REPL)

pip install ipython

ipython
# IPython special features
In [1]: ?str.split # View documentation
In [2]: ??str.split # View source code
In [3]: %timeit [x**2 for x in range(1000)] # Measure performance
In [4]: %history # Command history
In [5]: import os; os.getcwd()

# Tab auto-completion
In [6]: "hello". # Press Tab to see method list

Multi-line Input

# Entering multi-line code in the basic REPL
>>> def fibonacci(n):
... if n <= 1:
... return n
... return fibonacci(n - 1) + fibonacci(n - 2)
...
>>> fibonacci(10)
55

5. Code Quality Tools

black — Code Formatter

pip install black

# Format a single file
black script.py

# Format an entire directory
black src/

# Preview changes only (no actual modifications)
black --check script.py
black --diff script.py
# Before black
x = {'a':1,'b':2,'c':3}
def foo(a,b,c):
return a+b+c

# After black
x = {"a": 1, "b": 2, "c": 3}


def foo(a, b, c):
return a + b + c

ruff — Fast Linter (Rust-based)

pip install ruff

# Run linting
ruff check script.py

# Auto-fix issues
ruff check --fix script.py

# Format code (can replace black)
ruff format script.py

mypy — Static Type Checker

pip install mypy

# Run type checking
mypy script.py

# Strict mode
mypy --strict script.py
# Example of a type error caught by mypy
def add(a: int, b: int) -> int:
return a + b

result = add("hello", 42) # mypy error: expected int, got str

Pro Tips: .editorconfig and VS Code DevContainer

.editorconfig enforces editor settings across the entire team.

# .editorconfig (place at project root)
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.py]
indent_size = 4
max_line_length = 88

[*.json]
indent_size = 2

[*.yml]
indent_size = 2

VS Code DevContainer lets the entire team share the same development environment:

// .devcontainer/devcontainer.json
{
"name": "Python 3.12 Dev",
"image": "mcr.microsoft.com/devcontainers/python:3.12",
"features": {},
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-python.pylance",
"charliermarsh.ruff"
],
"settings": {
"python.defaultInterpreterPath": "/usr/local/bin/python"
}
}
},
"postCreateCommand": "pip install -r requirements.txt"
}

With this setup, every team member develops with the same Python version, extensions, and settings.


Now that your development environment is configured, it is time to write your first Python program. The next chapter starts with Hello, World! and covers the basic structure of Python code.

Advertisement