Python Wheels

Python wheels (*.whl) are the standard way of distributing Python modules. They are supported in Blender to make self-contained Python Extensions.

指南

  • By convention, always locate the files under ./wheels/.

系统要求

  • Wheels must be bundled unmodified from Python’s package index.

  • Wheels must include their dependencies.

  • Wheels filenames must match Python’s binary distribution specification: see docs. Wheels downloaded from Python’s package index will follow this convention.

  • Use forward slashes as path separators when listing them on the manifest.

How to Bundle Wheels

Python wheels (*.whl) can be bundled using the following steps.

Downloading Wheels

Download the wheel to the directory ./wheels/.

For wheels that are platform independent this example downloads jsmin:

  1. pip wheel jsmin -w ./wheels

For wheels that contain binary compiled files, wheels for all supported platforms should be included:

This example downloads pillow - the popular image manipulation module.

  1. pip download pillow --dest ./wheels --only-binary=:all: --python-version=3.11 --platform=macosx_11_0_arm64
  2. pip download pillow --dest ./wheels --only-binary=:all: --python-version=3.11 --platform=manylinux_2_28_x86_64
  3. pip download pillow --dest ./wheels --only-binary=:all: --python-version=3.11 --platform=win_amd64

The available platform identifiers are listed on pillow’s download page.

更新清单

In blender_manifest.toml include the wheels as a list of paths, e.g.

  1. wheels = [
  2. "./wheels/pillow-10.3.0-cp311-cp311-macosx_11_0_arm64.whl",
  3. "./wheels/pillow-10.3.0-cp311-cp311-manylinux_2_28_x86_64.whl",
  4. "./wheels/pillow-10.3.0-cp311-cp311-win_amd64.whl",
  5. ]

Now installing the package will extract the wheel into the extensions own site-packages directory.

运行

Once the extension has been installed you can check the module is being loaded by importing it in the Python console and printing it’s location:

  1. import PIL
  2. print(PIL.__file__)

Platform Builds

Wheels can severely impact the size of an extension. To mitigate this, it is possible to build different extension zip files for each unique required platform.

For this you need to use the --split-platforms option from the build command.

  1. blender --command extension build --split-platforms

例子

Manifest file excerpt:

  1. id = "my_addon_with_wheels"
  2. version = "1.0.0"
  3. platforms = ["windows-x64", "macos-x64"]
  4. wheels = [
  5. "./wheels/pillow-10.3.0-cp311-cp311-macosx_11_0_arm64.whl",
  6. "./wheels/pillow-10.3.0-cp311-cp311-manylinux_2_28_x86_64.whl",
  7. "./wheels/pillow-10.3.0-cp311-cp311-win_amd64.whl",
  8. ]

Generated files from --split-platforms:

  • my_addon_with_wheels-1.0.0-windows_x64.zip

  • my_addon_with_wheels-1.0.0-macos_x64.zip

Note

Even though there is a Linux-only wheel present, no Linux zip file is generated. This happens because the platforms field only has Mac and Windows.