Safeguard
Supply Chain•

Distribution package vs import package: why can pip install foo mislead?

A distribution package is what you install, an import package is what you import. PyPI does not tie the two names together, so guessing is risky.

Safeguard Security Team
4 min read

A distribution package is the thing you install, like a PyPI project. An import package is the thing you import in code. They usually share a name, but PyPI does not enforce that, so seeing import foo does not prove that pip install foo gives you the right code.

Definitions

The Python Packaging User Guide separates the two meanings of the word package.

TermWhat it isWhere you see it
Distribution packageInstallable software, or a specific file for one versionpip install, the dependencies list, PyPI search
Import packageA Python module that can contain submodulesimport statements in code

Most of the time, one distribution package provides one import package with a matching name. The guide calls that a convention only.

Why the names can differ

A distribution package can provide an import package with a different name, or more than one import package. The guide's examples: the Pillow distribution provides the import package PIL, kept for historical reasons because Pillow began as a fork of PIL, and the attrs distribution provides both attrs and attr. The guide also says PyPI and other indices do not enforce any relationship between the name of a distribution package and the import packages it provides.

That has a direct consequence. The guide states that you cannot blindly install the PyPI package foo because you see import foo, since this may install an unintended and potentially even malicious package.

How this goes wrong

  • Copying an install line from an AI answer or a forum post. The code imports a module, and the answer guesses the install name.
  • Fixing an ImportError by installing whatever has that name. A different project may own it.
  • Several distributions sharing one import name. The guide says import packages have no uniqueness requirement, and forks are a common reason.
  • Typosquats. Names that look like popular ones are a known pattern. Our posts on name normalization and lookalikes explain the mechanics.

What to do as a user

  1. Look up the project's own documentation or repository for the exact install name.
  2. Open the PyPI page and check the project links, owners and release history.
  3. Compare the install name to what the docs say, character by character.
  4. Add the verified name to your dependency list, not to a one off command.
  5. After installing, check what the distribution actually provides, by listing its installed files.

What to do as a library author

  • Document the install command and the import line side by side in your README.
  • If the two names differ, say so clearly.
  • Do not pick an import name that collides with a popular project.
  • Keep the README accurate, as in our README rendering fix guide.

Why dependency lists matter

Your declared dependencies are distribution names. Scanners, advisories and SBOMs all work on those. A clear inventory lets you see which distributions you rely on, whatever the import lines say.

Try it yourself

Click through it at your own pace, or open it full screen.

Open a package in the inventory and compare its name with what the code imports. Note that the inventory tracks distribution names.

Safeguard's SBOM and dependency scanning list the distributions a project declares. You can run a free scan.

Quick check

Is the install name always the import name?

Usually, but not always. The packaging guide says it is only a convention that PyPI does not enforce.

Is it safe to pip install a name from an import statement?

Not blindly. The guide warns it may install an unintended and potentially malicious package. Confirm the name from the project's own docs.

Can one distribution provide several import packages?

Yes. A distribution package can provide multiple import packages, as attrs does.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.