Dynamic class loading in Python 2.6: RuntimeWarning: Parent module 'plugins' not found while handling absolute import

前端 未结 5 2110
不知归路
不知归路 2020-12-30 23:37

I am working on a plugin system where plugin modules are loaded like this:

def load_plugins():
   plugins=glob.glob(\"plugins/*.py\")
   instances=[]
   for         


        
5条回答
  •  余生分开走
    2020-12-31 00:05

    The problem here is with the dot ('.') in the module name:

    imp.load_module('plugins.'+name, f, file, desc)

    Don't include a '.' after 'plugins', or Python will think it's a module path.

提交回复
热议问题