Lesson 21 · Python
Professional Practice: Modules, Packages & Virtual Environments
Grow scripts into projects: modules as files, packages with __init__.py, a virtual environment per project, pinned requirements.txt, and pyproject.toml to tie it together.
Prerequisites: Professional Practice: Testing with pytest
Learning objectives
By the end of this lesson, you will be able to:
- Explain what import really does, and use __name__ == '__main__' to keep files both importable and runnable
- Turn a folder of modules into an importable package with __init__.py, choosing absolute or relative imports deliberately
- Install third-party packages with pip and explain what PyPI is
- Create and activate a per-project virtual environment, and explain what it isolates
- Pin dependencies with requirements.txt and lay out a project with src/, tests/ and pyproject.toml