Home > Software design >  Deploying Python, takes forever to build wheel for cryptography
Deploying Python, takes forever to build wheel for cryptography

Time:09-30

I'm running a Django Python project in Heroku, and to support the Python cryptography package, my dockerfile contains instructions to first install the non-Python dependencies for that package:

run apk add openssl-dev cargo

And then my build log shows that deployment builds various wheels. The cryptography wheel takes several minutes to build:

  Building wheel for cryptography (PEP 517): started
  Building wheel for cryptography (PEP 517): still running...
  Building wheel for cryptography (PEP 517): still running...
  Building wheel for cryptography (PEP 517): finished with status 'done'
  Created wheel for cryptography: filename=cryptography-3.4.7-cp38-cp38-linux_x86_64.whl size=534047 sha256=8c3212278fa23bad7ecfbc54d036e8d35ba9308479d87e8ec39697aed26095dc

Is there any kind of precompiled wheel or buildpack or similar that I can use to more speed up my deployments?

CodePudding user response:

Based on your apk command it's likely you're running Alpine Linux. Alpine uses musl for its libc implementation and this has historically prevented the cryptography project from uploading binary wheels. However, with the acceptance of PEP 656 (and a lot of follow up work with auditwheel, pypa/manylinux containers, and pypa/warehouse allowing uploads) we can now upload musllinux wheels. cryptography uploaded a wheel for cryptography 3.4.8 (x86_64 arch) on September 19, 2021.

To get this wheel there are two prerequisites:

  1. You need to upgrade to the latest pip. No version older than 21.2.4 supports musllinux wheels.
  2. You need to ensure you're installing cryptography >= 3.4.8. Older versions do not have these wheels.

If you meet those requirements then pip install cryptography will no longer require a compiler (rust or gcc/clang) on Alpine.

  • Related