Ravindra Kumar Sonkar
Ravindra Kumar Sonkar

Reputation: 199

Python library not found. Set the PYTHON_LIBRARY environment variable with the path to a Python library

I have built a macOS application that using the python language. With the help of PythonKit, I'm using Python in swift. When I'm trying to use python then it getting an exception.

Python library not found. Set the PYTHON_LIBRARY environment variable with the path to a Python library

But When I add the environment variable ( PYTHON_LIBRARY(Key) : path/of/Python.framework(value)) in schema.

enter image description here

And also checked Disable Library Validation in Hardened Runtime capability.

enter image description here

With the help of both, it runs without exception.

But when I try to build an archive using Developer ID.

It is getting the same exception.

I don't know why it's running without exception in debugging mode, not in release mode.

Any Suggestions...

Upvotes: 2

Views: 1104

Answers (2)

user2555515
user2555515

Reputation: 1033

Even if it worked it would only on your own computer. Secondly PYTHON_LIBRARY should point to the actual library file not to the Python folder. You should:

  1. Copy the python library the resources in your application.

  2. Set the environment variable at runtime, not compile time as you do not know where the application is installed on the user machine

    let python_lib_path = "(ResourcesPath)/Python/libpython3.8.dylib" setenv("PYTHON_LIBRARY", python_lib_path, 0)

Upvotes: 0

kakaiikaka
kakaiikaka

Reputation: 4487

As of macOS 12.3,python2 is no longer a system built-in component. So consider porting your own python executable to your app.

Upvotes: 0

Related Questions