flask - python importlib no module named -


i using flask , have following structure

<root> manage_server.py cas <directory> --- __init__.py --- routes.py --- models.py --- templates <directory> --- static <directory> --- formmodules <directory> ------ __init__.py ------ baseformmodule.py ------ interview.py 

in routes.py, i'm trying create instance of interview class in interview module, so

my_module = "interview" module = importlib.import_module('formmodules."+my_module) 

i error here says

importerror: no module named formmodules.interview 

some info init files:

/cas/formmodules/__init__.py empty /cas/__init__.py initialize flask app.  

let me know if helpful know contents of of these files.

this 1 of classical relative vs absolute import problems.

formmodules exists relative cas, import_module absolute import (as from __future__ import absolute_imports). since formmodules cannot found via sys.path, import fails.

one way fix use relative import.

if name specified in relative terms, package argument must specified package act anchor resolving package name.

you might want try with:

module = importlib.import_module('.formmodules.' + my_module, package=__package__) 

note ..

the other option muck sys.path, isn't necessary, here.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -