Lesson 1.4

Modules, packages, and virtual environments

Installing packages globally means every project shares one set of versions, and the first version conflict breaks something you were not working on.

9mBeginner26.9k students

Overview

One environment per project, always

Installing packages globally means every project shares one set of versions, and the first version conflict breaks something you were not working on. A virtual environment gives each project its own isolated set.

A module is just a file, and a package a directory of them. The import guard that checks whether a file is being run directly is what lets the same file work as both a script and an importable module.

Record your dependencies in a file and pin versions for anything you will run again. An unpinned environment reproduces differently every month.

In this lesson you will:

  • Split a script into importable modules
  • Isolate dependencies per project
  • Pin what you installed so it reproduces

Resources

Previous Lesson
Next Lesson
Modules, packages, and virtual environments — Python Foundations for Data Work — Vertex