Python Overview & Environment Setup

Why Python is everywhere in backend development, CPython vs alternatives, installing Python, virtual environments with venv, dependency management with pip, and choosing an IDE.

BeginnerUpdated 2026-10-3088K views

Why Python for the Backend

Python is a dynamically typed, interpreted language known for readable syntax and an enormous ecosystem. On the backend it powers web frameworks (Django, FastAPI, Flask), data tooling, scripting, automation, AI services and more — the same language handles business logic and data pipelines.

  • Django: batteries-included full-stack framework, ideal for content sites and admin systems.
  • FastAPI: async, high-performance API framework with automatic OpenAPI docs.
  • Flask: minimal micro-framework when you want full control.

Installing Python

Download CPython 3.12+ from python.org, or use a package manager. On Windows tick 'Add Python to PATH'; on Linux check python3 --version.

python3 --version       # 查看版本
python3 -m pip --version

# Windows (winget)
winget install Python.Python.3.12

# Linux (apt)
sudo apt install python3 python3-pip python3-venv

Virtual Environments and pip

Never install project dependencies into the system Python — create an isolated virtual environment per project. Lock versions in requirements.txt (or pyproject.toml with uv/poetry) so production matches development.

python3 -m venv .venv          # 创建虚拟环境

# 激活
source .venv/bin/activate       # Linux / macOS
.venv\Scripts\activate          # Windows

pip install fastapi uvicorn     # 安装依赖
pip freeze > requirements.txt   # 锁定版本
pip install -r requirements.txt # 还原依赖

# 国内可加镜像加速
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple fastapi
Newer tooling: uv is a drop-in, blazing-fast replacement for pip+venv; poetry is popular for library-style projects.

First Program and Code Style

def greet(name: str) -> str:
    return f"Hello, {name}!"


if __name__ == "__main__":
    print(greet("BackendWiki"))
  • PEP 8 is the style guide: 4-space indent, snake_case functions, UPPER_CASE constants.
  • Type hints (def greet(name: str) -> str) are optional but standard in modern code; mypy can check them.

Friends & Partners