Published on

Python — How to download and extract a package using pip and wheel.

Authors
  • avatar
    Name
    Jimmy Lai
    Twitter

Introduction

I was looking at a project where 'cmd2' was being used to compile the script run time. As a result, pip and wheel are two essential Python tools for package management and packaging, respectively, when reviewing source code.

In this note, we'll go over how to use pip to download a package and wheel to extract/unpack it.

Step 1: Download aceye package to the current directory

pip download aceye 
python3 -m wheel unpack aceye

/tmp/aceye/aceye-2.0.2 % ls -lrtha
total 0
drwxr-xr-x   3 archie archie  520 Nov 19 08:12 ..
drwxr-xr-x   2 archie archie  140 Nov 19 08:12 aceye-2.0.2.dist-info
drwxr-xr-x 244 archie archie 5.0K Nov 19 08:12 aceye
drwxr-xr-x   4 archie archie   80 Nov 19 08:12 .



The content of the aceye file was extracted into the directory by wheel unpack.

The folder now contains all of the files required for the Python code to function without the need to install the package locally. This folder's source code can be included in another Python application.