Python: Create a WHL File

(Last Updated On: )

This post will just be a how-to on creating a whl file.

You need the following files:

Manifest.in:

  1. recursive-include <directory> *
  2. recursive-exclude tests *.py

Requirements.txt:

This file just holds your packages and the version.

Setup.py

You remove pytest and coverage from your whl file because you don’t want those applications being required when you deploy your code.

  1. from setuptools import find_packages
  2. from distutils.core import setup
  3. import os
  4. import json
  5.  
  6. if os.path.exists('requirements.txt'):
  7. req = [line.strip('\n') for line in open('requirements.txt') if 'pytest' not in line and 'coverage' not in line]
  8.  
  9. setup(
  10. include_package_data=True,
  11. name=<app_name>,
  12. version=<app-version>,
  13. description=<app_desc>,
  14. install_requires=req,
  15. packages=find_packages(excude=["*tests.*","*tests"]),
  16. classifiers=[
  17. "Programming Language :: Python || <python_Version>",
  18. "License || OSI Approved :: MIT License",
  19. "Operating System :: OS Independent",
  20. ],
  21. python_requires='>=<python_version>',
  22. package_dir={<directory>: <directory>},
  23. )

To Check Your Whl File

Install package

  1. pip install check-wheel-contents

Check WHL

  1. check-wheel-contents <PATH_TO_WHL>\<filename>.whl

Install WHL

This will deploy to <PATH_TO_PYTHON>\Lib\site-packages\<directory>

  1. <PATH_TO_PYTHON>\Scripts\pip3.7.exe install <PATH_TO_WHL>\<filename>.whl