This isn’t strictly-speaking a Panda issue; I’m nevertheless hoping that someone here will have some insight on it.
So, I’m attempting to use “importlib” for a certain feature of my game, calling “importlib.import_module” to dynamically load some modules.
However, while it works for one of my modules, in one hierarchy of directories, for some reason it doesn’t work for another module in a parallel hierarchy of directories!
In the case in which it doesn’t work, this is the error that I’m seeing:
<context above this point omitted for brevity and clarity>
File "/home/thaumaturge/Documents/My Game Projects/FantasySpaceShooter/SolarSystem.py", line 21, in loadMoon
module = importlib.import_module("Content.{0}.{1}.{2}.{2}".format(contentSet, MOON_DIR, moonID))
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'Content.TestDLC.Moons.DLCMoon.DLCMoon'; 'Content.TestDLC.Moons.DLCMoon' is not a package
Specifically, and as you can see in the error above, my call to “import_module” looks something like this:
importlib.import_module("Content.{0}.{1}.{2}.{2}".format(value1, value2, value3))
That call then corresponds to a hierarchy that looks something like this:
Content/
|
--- value1/
|
--- value2/
|
--- value3/
|
--- value3.py
All of the folders involved have “__init__.py” files, and all of the folders and files involved do exist, I do believe.
Specifically, here is an abridged image showing the two directories:
With these files and directories, if I’m not much mistaken the following call works:
importlib.import_module(Content.BaseGame.Moons.OssuaryMoon.OssuaryMoon)
While this call doesn’t:
importlib.import_module(Content.TestDLC.Moons.DLCMoon.DLCMoon)
Does anyone know what might be going wrong?