Dynamically loading subpackages
Posted: Mon Sep 07, 2020 8:19 am
I am unable to load any subpackages on my Linux box. I tested this on Windows (normal python installation) and this same code works fine there.

Syntax: Select all
from os.path import dirname, basename, isfile, join, abspath
import os
import glob
from importlib import import_module
from importlib.util import find_spec
subdir = join(dirname(__file__), "test")
subMod = import_module(subdir)
for file in os.listdir(subdir):
if file.endswith(".py"):
mod = "." + file.replace(".py", "")
print(find_spec(mod, subdir).loader)
