Search code examples
pythonmacospypipython-wheelpython-extensions

Create Python C extension using MacOS 10.15 (Catalina) that is backwards compatible (MacOS10.9+)


How can I create a Python C extension wheel for MacOS that is backwards compatible (MacOS 10.9+) using MacOS 10.15?

This is what I have so far:

export MACOSX_DEPLOYMENT_TARGET=10.9
python -m pip wheel . -w wheels --no-deps
python -m pip install delocate
for whl in wheels/*.whl; do
    delocate-wheel -w wheels_fixed -v "$whl"
done

Unfortunately, pip wheel generates a file myapp-0.0.1-cp37-cp37m-macosx_10_15_x86_64.whl, and unlike auditwheel on Linux, delocate-wheel does not modify the name of the wheel. As a result, if I upload it on PyPI using twine, only users with MacOS 10.15 are able to install it using pip. I guess I could manually rename it to myapp-0.0.1-cp37-cp37m-macosx_10_9_x86_64.whl, but this does not sound right to me.

For the builds I am just using the GitHub Actions MacOS virtual machines.

Thank you.

PS: The compiler used for the build is GCC9


Solution

  • I found the solution to my problem and I will post the answer here in case someone else has the same problem.

    In order to fix the problem I had to also set export MACOSX_DEPLOYMENT_TARGET=10.9 before I install python using pyenv. Now pip wheel creates my wheel with the tag macosx_10_9_x86_64.

    Thank you.

    PS: When installing python via pyenv, python is compiled from source, and somehow it takes into account the flag MACOSX_DEPLOYMENT_TARGET.