How do I install a Python package with a .whl file?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
To install a Python package from a .whl file, run pip install path/to/package.whl. Wheel files are pre-built binary distributions that install faster than source distributions because they skip the compilation step. They are the standard format for distributing Python packages and have replaced eggs since PEP 427.
What Is a .whl File?
A .whl file is a ZIP archive with a specific naming convention that tells pip which Python version, platform, and ABI it targets. The format follows this pattern:
For example:
Breaking this down:
| Component | Value | Meaning |
| Package | numpy | Package name |
| Version | 1.26.4 | Package version |
| Python tag | cp312 | CPython 3.12 |
| ABI tag | cp312 | CPython 3.12 ABI |
| Platform tag | macosx_11_0_arm64 | macOS 11+ on Apple Silicon |
A wheel with py3-none-any in its name is a pure Python package that works on any platform and any Python 3 version.
Basic Installation
Step 1: Verify Your pip Version
Pip 1.4+ supports wheel files natively. Check and upgrade if needed:
Step 2: Install the Wheel File
Navigate to the directory containing the .whl file and run:
Or provide the full path without changing directories:
Step 3: Verify the Installation
Installing into a Virtual Environment (Recommended)
Always install packages into a virtual environment to avoid conflicts with system Python:
Where to Download .whl Files
PyPI (Official Source)
Download wheels directly from PyPI when you need offline installation or a specific version:
Unofficial Binaries (Windows)
For Windows packages that are hard to compile (like GDAL, rasterio, or Shapely), Christoph Gohlke's archive at https://www.lfd.uci.edu/~gohlke/pythonlibs/ historically provided pre-built wheels. This site is now archived, but many of these packages now publish official wheels on PyPI.
Building Your Own Wheel
You can build a wheel from a source distribution:
Installing Multiple Wheels and Dependencies
Install Multiple Wheels from a Directory
Handle Dependencies Automatically
Pip resolves dependencies from PyPI by default. If a wheel depends on other packages, pip downloads and installs them automatically:
For fully offline installation, download all dependencies first:
Wheel vs Source Distribution vs Egg
| Feature | Wheel (.whl) | Source dist (.tar.gz) | Egg (.egg) |
| Format | ZIP archive | Compressed tarball | ZIP archive |
| Installation speed | Fast (no compilation) | Slow (may compile C extensions) | Fast |
| Build step required | No | Yes (runs setup.py) | No |
| PEP standard | PEP 427 (current) | PEP 625 | Deprecated |
| Arbitrary code at install | No | Yes (setup.py runs) | No |
| Security | Safer | Riskier (arbitrary code) | Safer |
Wheels are preferred because they do not execute arbitrary code during installation. Source distributions run setup.py, which can execute anything.
Compatibility and Platform Matching
Check Your Python and Platform Tags
To install a wheel, your environment must match the wheel's tags. Check what your pip supports:
This shows supported tags like:
Force Install an Incompatible Wheel
If you are certain a wheel is compatible despite tag mismatches (for example, a manylinux2014 wheel on a newer Linux):
For truly incompatible wheels, rename the file to match your platform (not recommended, and may cause runtime crashes).
Common Pitfalls
- "is not a supported wheel on this platform": The wheel's Python version, ABI, or platform tag does not match your environment. Run
pip debug --verboseto see which tags your pip supports. You likely downloaded a wheel for the wrong Python version or OS. - "No matching distribution found": When using
pip installwith--find-links, pip might skip the local.whlfile if a newer version exists on PyPI. Add--no-indexto force pip to use only local files. - Using
sudo pip install: This installs packages into the system Python, which can break OS-level tools. Use virtual environments instead. If you must install system-wide, usepip install --user package.whl. - Pip version too old: Pip versions before 1.4 do not support wheel files. Pip versions before 19.0 do not support
manylinux2010wheels. Always upgrade pip first:pip install --upgrade pip. - Missing build dependencies for source fallback: If a wheel is not available and pip falls back to building from source, you need compilers (gcc, MSVC) and development headers installed. The wheel format exists specifically to avoid this problem.
- Confusing
pip install wheelwith installing a.whlfile: The package namedwheelis a build tool. Installing it withpip install wheeldoes not install any.whlfile you have downloaded.
Summary
- Install a wheel file with
pip install path/to/package.whl. No additional tools required beyond pip 1.4+. - Wheels are pre-built binary packages that skip compilation, making installation faster and safer than source distributions.
- Always use a virtual environment to avoid polluting your system Python.
- Download wheels for offline use with
pip download package -d ./wheels/, then install withpip install --no-index --find-links=./wheels/ package. - Check platform compatibility with
pip debug --verboseif you get "not a supported wheel on this platform" errors. - Prefer wheels over source distributions for security: wheels cannot execute arbitrary code during installation.
Related reading
- How do I install a Python package with a .whl file?
- How do I install opencv using pip?
- How do I install pip on macOS or OS X?
- How do I install pip on macOS or OS X?
- How do I install pip on Windows?
- How do I install Python 3 on an AWS EC2 instance?
- How do I install Python OpenCV through Conda?
- How do I install tensorflow_text?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.