OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

PythonKit integration with Swift - Crashing on release due to module import

  • Thread starter Thread starter reidemption
  • Start date Start date
R

reidemption

Guest
I have a project that is using Swift (for interface) and Python (for function) for a Mac application.

I added PythonKit as a dependency and after: • removing "App Sandbox" from "Signing & Capabilities" • turning "Enable Hardened Runtime" off • Setting environment variable "PYTHON_LIBRARY" to "/opt/homebrew/bin/python3.11"

Now everything works as hoped and when I run it works great.

However, now I archive the Xcode project -> Distribute -> Custom -> Copy App. It creates an instance of the application to where I save it and as soon as I open it it opens for a few milliseconds (the window never opens) and it immediately crashes with this warning window:

Code:
-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

Version:               1.0 (1)
Code Type:             ARM-64 (Native)
Parent Process:        launchd [1]

OS Version:            macOS 14.0 (23A344)
Report Version:        12

Exception Type:        EXC_BREAKPOINT (SIGTRAP)
Exception Codes:       0x0000000000000001, 0x000000019f534658

Termination Reason:    Namespace SIGNAL, Code 5 Trace/BPT trap: 5
Terminating Process:   exc handler [97502]

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   libswiftCore.dylib          0x19f534658 _assertionFailure(_:_:file:line:flags:) + 268
1   libswiftCore.dylib          0x19f5a0cf8 swift_unexpectedError + 516
2   Filex                       0x102576428 PythonInterface.import(_:) + 148 (Python.swift:707)
3   Filex                       0x10256f7e8 PythonAPI.init() + 568 (PythonAPI.swift:24)
4   Filex                       0x10256f5a4 PythonAPI.__allocating_init() + 44
5   Filex                       0x102541a30 implicit closure #2 in implicit closure #1 in variable initialization expression of Main._pythonAPI + 28
6   SwiftUI                     0x1bb15ab5c 0x1ba412000 + 13929308

Notes: It looks like it's crashing at this function:

Code:
public init() {        
   // Initialize Python
   system = Python.import("sys")
   system.path.append("/Users/reidhtaylor/Documents/Projects/Python/Filex/FilexBackend")
        
   // Get main file
   main = Python.import("main") //!!!! AT THIS LINE #24 !!!!//
}

First of all I don't understand why it works fine when I "Run" the project but "Archive doesn't work". Also I don't get how system.path.append should work cause won't everyones path be different when I build the app? And yes the main.py file is in the FilexBackend folder and it works when Running the project.

I tried settings "Strip Style" to only "Debugging Symbols" (didn't work) and I couldn't find the settings "Enable Bitcode" to try turning it off (which is a fix I saw online)
<p>I have a project that is using Swift (for interface) and Python (for function) for a Mac application.</p>
<p>I added PythonKit as a dependency and after:
• removing "App Sandbox" from "Signing & Capabilities"
• turning "Enable Hardened Runtime" off
• Setting environment variable "PYTHON_LIBRARY" to "/opt/homebrew/bin/python3.11"</p>
<p>Now everything works as hoped and when I run it works great.</p>
<p>However, now I archive the Xcode project -> Distribute -> Custom -> Copy App. It creates an instance of the application to where I save it and as soon as I open it it opens for a few milliseconds (the window never opens) and it immediately crashes with this warning window:</p>
<pre><code>-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

Version: 1.0 (1)
Code Type: ARM-64 (Native)
Parent Process: launchd [1]

OS Version: macOS 14.0 (23A344)
Report Version: 12

Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x000000019f534658

Termination Reason: Namespace SIGNAL, Code 5 Trace/BPT trap: 5
Terminating Process: exc handler [97502]

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libswiftCore.dylib 0x19f534658 _assertionFailure(_:_:file:line:flags:) + 268
1 libswiftCore.dylib 0x19f5a0cf8 swift_unexpectedError + 516
2 Filex 0x102576428 PythonInterface.import(_:) + 148 (Python.swift:707)
3 Filex 0x10256f7e8 PythonAPI.init() + 568 (PythonAPI.swift:24)
4 Filex 0x10256f5a4 PythonAPI.__allocating_init() + 44
5 Filex 0x102541a30 implicit closure #2 in implicit closure #1 in variable initialization expression of Main._pythonAPI + 28
6 SwiftUI 0x1bb15ab5c 0x1ba412000 + 13929308
</code></pre>
<p>Notes: It looks like it's crashing at this function:</p>
<pre><code>public init() {
// Initialize Python
system = Python.import("sys")
system.path.append("/Users/reidhtaylor/Documents/Projects/Python/Filex/FilexBackend")

// Get main file
main = Python.import("main") //!!!! AT THIS LINE #24 !!!!//
}
</code></pre>
<p>First of all I don't understand why it works fine when I "Run" the project but "Archive doesn't work". Also I don't get how system.path.append should work cause won't everyones path be different when I build the app? And yes the main.py file is in the FilexBackend folder and it works when Running the project.</p>
<p>I tried settings "Strip Style" to only "Debugging Symbols" (didn't work) and I couldn't find the settings "Enable Bitcode" to try turning it off (which is a fix I saw online)</p>
 

Latest posts

G
Replies
0
Views
1
Gamal Othman
G
Top