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.
And also checked Disable Library Validation in Hardened Runtime capability.
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…
2
Answers
As of macOS 12.3,python2 is no longer a system built-in component. So consider porting your own python executable to your app.
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:
Copy the python library the resources in your application.
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)