Can I exclude libraries from auditwheel repair?

Question:

I’m using manylinux2014_x86_64 build some precompiled linux wheels for a python library that acts as an API to a C++ library involving CUDA. I create the wheels with pip wheel, then run auditwheel repair to include external libraries in the wheels (my c++ library, pybind11, etc.)

The problem is that it wants to package CUDA runtime and driver libraries into the wheel. Ideally I’d like to leave the CUDA installation up to the user rather than having to include it in the python wheel (I’m not even sure exactly how redistributable it is).

Is anyone aware of a way to blacklist the cuda libs from auditwheel repair? Or perhaps another better way of doing this?

Asked By: catflaps

||

Answers:

There is a way, but it kind of defeats the purpose of auditwheel repair.

You need to install auditwheel as a Python module, then import it in your own python script and monkey patch some values that specify repair policies.

# Monkey patch to not ship libjvm.so in pypi wheels
import sys

from auditwheel.main import main
from auditwheel.policy import _POLICIES as POLICIES

# libjvm is loaded dynamically; do not include it
for p in POLICIES:
    p['lib_whitelist'].append('libjvm.so')

if __name__ == "__main__":
    sys.exit(main())

This snippet is from the diplib project, which does what you wish for Java libraries. You would need to modify this script to cover libraries you need to whitelist.

This script then needs to be invoked by a Python 3.x interpreter or it will fail. You can repair Python 2.7 wheels this way just fine if you need to. The diplib project also shows an example invocation that needs to happen in a manylinux docker container.

#!/bin/bash
# Run this in a manylinux2010 docker container with /io mounted to some local directory

# ...

/opt/python/cp37-cp37m/bin/python -m pip install cmake auditwheel  # ignore "cmake"

# ...

export AUDITWHEEL=`pwd`/diplib/tools/travis/auditwheel  # the monkey patch script

# ...

/opt/python/cp37-cp37m/bin/python $AUDITWHEEL repair pydip/staging/dist/*.whl

# ...
Answered By: predi

Right now, this is possible using auditwheel repair --exclude flag.

Answered By: rdbisme
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.