如何动态导入自己的模块?

时间:2019-02-03 08:07:02

标签: python-import

我具有以下项目结构:

capslayer/
   ..data/
   ....dataset/
   ......stanford_drone/
   ........reader.py
   ........writer.py
   ........init.py

在main.py中,具有以下代码结构。

  dataset = "capslayer.data.datasets." + cfg.dataset
  data_loader = import_module(dataset).DataLoader(path=cfg.data_dir,
                                                splitting=cfg.splitting,
                                                num_works=cfg.num_works)

但是出现以下错误:

Traceback (most recent call last):
File "main.py", line 237, in <module>
tf.app.run()
File "/home/atakan/anaconda3/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 124, in run
_sys.exit(main(argv))
File "main.py", line 225, in main
data_loader = import_module(dataset).DataLoader(path=cfg.data_dir,
File "/home/atakan/anaconda3/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 948, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'capslayer.data.datasets.stanford_drone'

那么,我该如何解决此问题?如何导入stanford_drone模块?谢谢...

0 个答案:

没有答案