Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Python Packaging Cheatsheet

This is an area for me to put my notes/resources to do with creating Python packages before I forget about them. When I learn how to work around an issue, I'll put my notes here.

Resources

Wheel Files

  • A wheel file is a single "bundle file" for your package that you can install from. This may be the simplest way to distribute and install your package.
  • Installing from a wheel file can be much faster than installing from a GitHub repository for heavy packages (machine learning or large assets).

Build the wheel file with:

python setup.py bdist_wheel

Manifest.in

Configuring setup.py with package_data option will allow things to be installed correctly when pip installing from a GitHub repository or URL, but only if data assets are included in the Manifest.in file, will the assets be included in the generated wheel file.

Use graft line to include all files within a directory in your package. E.g.

graft src/my-package/data

LFS Issues

If using GitHub/GitLab for a source to install packages from with pip, and the repository makes use of LFS, then ensure you have LFS installed on your client e.g. sudo apt-get install git-lfs -y. I ran into this when trying to install packages inside a Docker container.

Last updated: 6th October 2021
First published: 6th October 2021