skip to Main Content

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…

2

Answers


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

    Login or Signup to reply.
  2. 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)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search