Application is not able to load libz.1.dylib

I have created a test app using python3.9.12 version and pyinstaller version 5.0.1. The .pkg is getting created successfully but during runtime getting the below error:

ImportError: dlopen(/Applications/TestApp/Contents/MacOS/lib-dynload/binascii.cpython-39-darwin.so, 2): Library not loaded: /opt/local/lib/libz.1.dylib

  Referenced from: /Applications/TestApp/Contents/MacOS/lib-dynload/binascii.cpython-39-darwin.so

  Reason: no suitable image found.  Did find: /opt/local/lib/libz.1.dylib: code signature in (/opt/local/lib/libz.1.dylib) not valid for use in process using Library Validation: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.

I have tried disabling library validation, it dint work for me. are there any solution available for this?

It sounds like your main app has the hardened runtime enabled, which makes it tricky for it to load unsigned code. The best way to fix this depends on your deployment goals. You wrote:

The .pkg is getting created successfully

How far to intend to deploy this? If you want to deploy it widely, the best path forward is to:

  • Leave the hardened runtime enabled

  • Embed a copy of any libraries you depend on within your app, signing them as your code

  • Alternatively, if the case of libz, use the one built-in to macOS

This setup allows you to leave the hardened runtime fully enabled; you don’t even need to disable library validation.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

  1. download code of zlib
  2. compile
  3. copy the dylib to the path where you need
cd ~/Downloads/zlib-1.3
./configure
make
ls -la *.dylib
cp libz.1.3.dylib /opt/local/lib/libz.1.dylib
Application is not able to load libz.1.dylib
 
 
Q