HOWTO · Python

How to Install a Python Package .Whl File

Learn how to choose a compatible Python wheel, install a local .whl file with pip, and troubleshoot common installation errors.

On this page

To install a Python .whl file, choose a wheel that matches your Python interpreter and platform, then run python -m pip install "/path/to/package.whl" from a terminal. This installs the package into the environment belonging to that python command. A wheel is a ready-to-install package distribution; you normally install it with pip rather than unpacking it yourself.

Understanding .whl Files

A wheel is a built distribution format for Python packages. It is a ZIP-based archive with package files and metadata in a layout that installation tools understand. A wheel can contain Python code, compiled extensions, or both. Installing a compatible wheel usually avoids building the package from source on your machine.

The filename identifies the distribution, version, and compatibility tags, and it is followed by the .whl extension. Those tags describe such details as the Python implementation and version, the application binary interface (ABI), and the operating system or processor platform. A wheel marked py3-none-any is generally intended for Python 3 without a platform-specific binary component; other wheels can be limited to particular Python builds or systems.

Choose a Compatible Wheel

Get the file from the package publisher or a package index you trust. Before downloading, check the package’s installation instructions and choose a wheel whose tags match the Python interpreter and machine where you plan to install it. A file built for another operating system, processor architecture, or Python ABI may not be usable, even when its package name is correct.

To see which interpreter a command refers to, run python --version and python -m pip --version. On systems where the Python 3 command is python3, use python3 consistently. If you have multiple Python installations or a virtual environment, activate the intended environment first, or use its interpreter path directly. This avoids installing into one environment and then trying to import the package from another.

A local wheel is useful when the target machine has limited or no internet access. Download the wheel and any required dependency wheels on a connected machine, transfer them to the target, and install from the local files. The --no-index and --find-links options can tell pip to look in a local directory for dependencies; they do not make missing dependencies available automatically.

Install a .whl File with pip

Use python -m pip so pip runs under the interpreter named by python. Replace the example path with the location and filename of your wheel:

from pathlib import Path
import csv
import hashlib
import subprocess
import sys
import tempfile
import zipfile

with tempfile.TemporaryDirectory() as directory:
    root = Path(directory)
    wheel = root / "sample_wheel_demo-1.0-py3-none-any.whl"
    dist_info = "sample_wheel_demo-1.0.dist-info"

    files = {
        "sample_wheel_demo.py": "message = 'wheel installed'\n",
        f"{dist_info}/METADATA": (
            "Metadata-Version: 2.1\n"
            "Name: sample-wheel-demo\n"
            "Version: 1.0\n\n"
        ),
        f"{dist_info}/WHEEL": (
            "Wheel-Version: 1.0\n"
            "Generator: example\n"
            "Root-Is-Purelib: true\n"
            "Tag: py3-none-any\n"
        ),
    }
    record_path = f"{dist_info}/RECORD"
    with zipfile.ZipFile(wheel, "w") as archive:
        for name, contents in files.items():
            archive.writestr(name, contents)
        rows = []
        for name, contents in files.items():
            digest = hashlib.sha256(contents.encode()).digest()
            import base64
            encoded = base64.urlsafe_b64encode(digest).rstrip(b"=").decode()
            rows.append((name, f"sha256={encoded}", str(len(contents.encode()))))
        rows.append((record_path, "", ""))
        import io
        record = io.StringIO()
        csv.writer(record, lineterminator="\n").writerows(rows)
        archive.writestr(record_path, record.getvalue())

    target = root / "installed"
    result = subprocess.run(
        [sys.executable, "-m", "pip", "install", "--no-index", "--no-deps",
         "--target", str(target), str(wheel)],
        capture_output=True, text=True,
    )
    if result.returncode == 0:
        print("Installed sample-wheel-demo 1.0")
    else:
        print("Installation failed:", result.stderr.strip())
        raise SystemExit(result.returncode)

This self-contained example creates a small wheel in a temporary directory and asks the current interpreter’s pip to install it into a separate target directory. For an existing wheel, the command pattern is python -m pip install "/path/to/package.whl". Quoting the path handles spaces in directory or file names. On Windows, use a path such as "C:\Users\Ada\Downloads\package.whl"; in PowerShell or Command Prompt, the same quoted argument form works.

If you downloaded the wheel and its dependencies for offline use, point pip at their directory: python -m pip install --no-index --find-links "/path/to/wheels" "/path/to/package.whl". Without those local dependency files, pip cannot fetch dependencies while offline.

Troubleshoot Installation Errors

  • No matching distribution or an unsupported wheel tag: Check that the wheel’s Python, ABI, and platform tags fit the interpreter and machine. Download a matching build from the publisher, or follow its instructions for another supported installation route.
  • A dependency is missing: Read the pip error to identify the dependency. Install a compatible dependency wheel as well, or, when online access is available, let pip resolve it from the configured package index. For an offline install, include all required dependency wheels in the local directory.
  • The package installs but cannot be imported: Compare python -m pip --version with the interpreter used to run your application. Run both through the same interpreter or activate the correct virtual environment before installing.
  • Permission is denied: Prefer a virtual environment that you own. A user-level install with python -m pip install --user ... may suit a system interpreter, but some managed environments disable it; follow the environment administrator’s guidance there.
  • The pip command is not found: Invoke pip as python -m pip or python3 -m pip. If that reports that pip is unavailable, use the Python distribution’s documented pip setup instructions for that interpreter.
  • A Git repository contains a wheel: Cloning the repository only downloads its tracked files; it does not install a package or guarantee that a compatible wheel is present. Follow the project maintainer’s instructions, locate a published wheel asset, and install that local file with pip. Treat repository code and downloaded artifacts according to the source’s trust and verification practices.

For any failure, use the complete pip message to identify whether the issue is the selected wheel, a dependency, the Python environment, or permissions. Correct that cause, then rerun the installation with the intended interpreter.