Search GimmeJob

Type at least 2 characters. Enter also searches by meaning.
Python interview question
Modules, packaging & environmentsSeniorOccasionalTheory

What is the difference between a source distribution (sdist) and a wheel, and why do wheels install faster?

Answer

A source distribution (`.tar.gz`) contains a package's raw source code plus build instructions, and installing it may require running a build step, including compiling any C extensions, on the installing machine at install time. A wheel (`.whl`) is a pre-built, ready-to-install archive — for a pure-Python package it just needs unzipping into `site-packages`, and for a package with compiled extensions, a platform-specific wheel already contains the compiled binary for that OS and Python version, so `pip` never needs a working C compiler on the installing machine to succeed.

Strong answer includes

  • sdist ships source plus build instructions, may compile at install time
  • wheel is pre-built and ready to install, often just an unzip
  • platform-specific wheels avoid needing a compiler on the install machine

Practical example

Installing a NumPy wheel takes seconds because a precompiled binary matching your OS and Python version is downloaded, while building NumPy from its sdist on a machine without the right compiler toolchain can fail outright.

#packaging#wheel

Sources

Python Packaging User GuidePython Packaging Authority · Project metadata, wheels, dependency and environment management practices