Python and Swift integration with PythonKit crashes on build

I got python all embedded with my project using PythonKit in Xcode and my python files are built as bundle resources so everything is working when I archive and then export as copy build. It loads python from the resources and then loads my scripts.

Big problem though is whenever I send the app to another computer to test it, it crashes immediately upon opening with this error:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Translated Report (Full Report Below)
-------------------------------------
Process: Filex [27455]
Path: /private/var/folders/*/Filex.app/Contents/MacOS/Filex
Identifier: com.scorpionstudios.Filex
Version: 1.0 (1)
Code Type: X86-64 (Native)
Parent Process: launchd [1]
User ID: 501
Date/Time: 2024-06-29 13:55:12.8411 -0700
OS Version: macOS 14.5 (23F79)
Report Version: 12
Bridge OS Version: 8.5 (21P5077)
Anonymous UUID: 0BCB58F4-9F99-4BF4-18CD-32398D822138
Sleep/Wake UUID: 2CD8D2B8-6C7E-4A0A-9B76-EFCB335AD370
Time Awake Since Boot: 1200000 seconds
Time Since Wake: 121 seconds
System Integrity Protection: enabled
Crashed Thread: 0
Exception Type: EXC_BAD_INSTRUCTION (SIGILL)
Exception Codes: 0x0000000000000001, 0x0000000000000000
Termination Reason: Namespace SIGNAL, Code 4 Illegal instruction: 4
Terminating Process: exc handler [27455]
Kernel Triage:
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter
Thread 0 Crashed:
0 libswiftCore.dylib 0x7ff81796cd9f _assertionFailure(_:_:file:line:flags:) + 351
1 libswiftCore.dylib 0x7ff8179c4a48 swift_unexpectedError + 840
2 Filex 0x10442930f PythonInterface.import(_:) + 111
3 Filex 0x1044238e4 PythonAPI.init() + 5796
4 Filex 0x104422231 PythonAPI.__allocating_init() + 33
5 Filex 0x1043f5918 implicit closure #2 in implicit closure #1 in variable initialization expression of Main._pythonAPI + 24
6 SwiftUI 0x7ff9148f840f 0x7ff913d73000 + 12080143
</code>
<code>Translated Report (Full Report Below) ------------------------------------- Process: Filex [27455] Path: /private/var/folders/*/Filex.app/Contents/MacOS/Filex Identifier: com.scorpionstudios.Filex Version: 1.0 (1) Code Type: X86-64 (Native) Parent Process: launchd [1] User ID: 501 Date/Time: 2024-06-29 13:55:12.8411 -0700 OS Version: macOS 14.5 (23F79) Report Version: 12 Bridge OS Version: 8.5 (21P5077) Anonymous UUID: 0BCB58F4-9F99-4BF4-18CD-32398D822138 Sleep/Wake UUID: 2CD8D2B8-6C7E-4A0A-9B76-EFCB335AD370 Time Awake Since Boot: 1200000 seconds Time Since Wake: 121 seconds System Integrity Protection: enabled Crashed Thread: 0 Exception Type: EXC_BAD_INSTRUCTION (SIGILL) Exception Codes: 0x0000000000000001, 0x0000000000000000 Termination Reason: Namespace SIGNAL, Code 4 Illegal instruction: 4 Terminating Process: exc handler [27455] Kernel Triage: VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter Thread 0 Crashed: 0 libswiftCore.dylib 0x7ff81796cd9f _assertionFailure(_:_:file:line:flags:) + 351 1 libswiftCore.dylib 0x7ff8179c4a48 swift_unexpectedError + 840 2 Filex 0x10442930f PythonInterface.import(_:) + 111 3 Filex 0x1044238e4 PythonAPI.init() + 5796 4 Filex 0x104422231 PythonAPI.__allocating_init() + 33 5 Filex 0x1043f5918 implicit closure #2 in implicit closure #1 in variable initialization expression of Main._pythonAPI + 24 6 SwiftUI 0x7ff9148f840f 0x7ff913d73000 + 12080143 </code>
Translated Report (Full Report Below)
-------------------------------------

Process:               Filex [27455]
Path:                  /private/var/folders/*/Filex.app/Contents/MacOS/Filex
Identifier:            com.scorpionstudios.Filex
Version:               1.0 (1)
Code Type:             X86-64 (Native)
Parent Process:        launchd [1]
User ID:               501

Date/Time:             2024-06-29 13:55:12.8411 -0700
OS Version:            macOS 14.5 (23F79)
Report Version:        12
Bridge OS Version:     8.5 (21P5077)
Anonymous UUID:        0BCB58F4-9F99-4BF4-18CD-32398D822138

Sleep/Wake UUID:       2CD8D2B8-6C7E-4A0A-9B76-EFCB335AD370

Time Awake Since Boot: 1200000 seconds
Time Since Wake:       121 seconds

System Integrity Protection: enabled

Crashed Thread:        0

Exception Type:        EXC_BAD_INSTRUCTION (SIGILL)
Exception Codes:       0x0000000000000001, 0x0000000000000000

Termination Reason:    Namespace SIGNAL, Code 4 Illegal instruction: 4
Terminating Process:   exc handler [27455]

Kernel Triage:
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter

Thread 0 Crashed:
0   libswiftCore.dylib                    0x7ff81796cd9f _assertionFailure(_:_:file:line:flags:) + 351
1   libswiftCore.dylib                    0x7ff8179c4a48 swift_unexpectedError + 840
2   Filex                                    0x10442930f PythonInterface.import(_:) + 111
3   Filex                                    0x1044238e4 PythonAPI.init() + 5796
4   Filex                                    0x104422231 PythonAPI.__allocating_init() + 33
5   Filex                                    0x1043f5918 implicit closure #2 in implicit closure #1 in variable initialization expression of Main._pythonAPI + 24
6   SwiftUI                               0x7ff9148f840f 0x7ff913d73000 + 12080143

I can’t figure out why this is happening??? If I comment out this line of code the error doesn’t happen:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>var main : PythonObject = Python.import("main")
</code>
<code>var main : PythonObject = Python.import("main") </code>
var main : PythonObject = Python.import("main")

“main” is a file module (main.py) that is is included in the apps bundle resources and I added the resource path Bundle.main.path(forResource: “Resources”, ofType: nil). It works on my computer when I build it so I don’t know why it doesn’t work on others??? Any ideas?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật