This code works:
module = imp.load_source("module", os.path.join(os.getcwd(), file_name))
This code doesn't:
module = importlib.import_module(os.path.join(os.getcwd(), file_name))
With the error:
ModuleNotFoundError: No module named 'C:\\Users\\...\\functions'
For reference, my module's location is 'C:\\Users\\...\\functions.py'
I've tried referencing via a relative directory, and I've also got init.py in the same directory that I'm working in to ensure that its a package. I've read through the very well written answer here and learned that it might be because the directory my script is running from is the same as the file I'm trying to read from. However, its answer is for "normal" imports, whereas my use-case requires is via imp
vs importlib
.
This feels simple, but I'm at a total loss. Any advice would be greatly appreciated.