I can't get this to work, unfortunately. What it gives me is the current directory in DerivedData, which doesn't have my module. Adding the home folder to PYTHONPATH works using pathlib:
let pathLib = Python.import("pathlib")
let home = pathLib.Path.home()
So I put my module there, but I still can't load classes from it (I've double-checked from the terminal, and it works fine there).
let myModule = try? Python.attemptImport("myModule")
I also tried:
let myClass = try? Python.attemptImport("myModule.myClass")
A weird additional detail about this is that, even though
myModule isn't recognized, I do see a
.pyc file for myClass appear in the
__pycache__. Strange, no?
UPDATE: Just to get going, I've tried installing myModule via pip, but it still fails with a
No module named ... error in PythonKit. Maybe some kind of permissions issue? This is a macOS app, with no Sandbox or Hardened Runtime capabilities added, and I'm running in debug mode only (I'm just building an in-house utility app, at the moment). I have changed my python version to a conda virtualenv using
setenv, but I'm double-checking my work in the terminal, running that virtualenv, so things should be fine, unless it's some specific problem that PythonKit has with virtualenvs.
UPDATE 2: Interestingly, it seems I can get it loading by just using a String for my home folder, not pathlib. No idea why that would be (probably some other issue I'm not seeing), but at least I'm on to my next error! Haha... My module is trying to use cuda, which isn't on this machine, so have to edit all the
.device stuff for macOS.