Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python

How to install a Python package with a .whl file

Anjana Shankar

What is a .whl file?

A .whl file, which is also known as a wheel, is the new standard of Python packaging. It allows for more consistent packaging, distribution, and faster installs.

Wheels are essentially zip files that tell Python installers about all the supported versions.

Terminal 1
Terminal

Installation of a .whl file with pip3

If we’ve used pip to install Python packages before, chances are that we already have wheels installed on our system. In the terminal above pip is preinstalled for us. Let’s try to install a Python package of our choice using pip. When we observe the download, we’ll see wheel in it. As practice, we can try installing Boto3.

Boto3 is a Python package for AWS SDK. Let’s install Boto3 with the following command. The terminal given above is set up with the prerequisites for pip installation.

pip3 install boto3

Download a .whl file

These are the steps we follow to download a wheel to a specific location on our system:

pip download --only-binary :all: --dest . --no-cache <package_name>

Downloading wheels can be useful for building our own repository behind a firewall.

Install a downloaded .whl file

We can install the downloaded .whl file using pip:

pip install <filename>.whl

Terminal 1
Terminal

The terminal above has been set up with pip3. These can be used for executing the commands given below, which will download a wheel to our system and then help us install it.

Let's download a urllib3 wheel and install it:

pip3 download --only-binary :all: --dest . --no-cache urllib3

The command given above downloads the urllib3 wheel on our system. We can obtain its details using ls.

widget

This wheel can be installed using the following command:

pip3 install urllib3-1.26.10-py2.py3-none-any.whl

Once the package is installed, we can execute a Python shell and try importing the package:

python3

>> import urllib3

Conclusion

This answer covers the topic of Python wheels as an installation package, and pip being the package manager that helps install it. Wheels are typically small in size. This makes their movement across networks fast, resulting in faster installation times.

RELATED TAGS

python
RELATED COURSES

View all Courses

Keep Exploring