Python ImportError:没有名为ext的模块

时间:2013-11-21 05:07:26

标签: python-2.7 vagrant

当我运行我的代码时,我收到以下错误ImportError: No module named ext

代码示例导致错误

import module.model
module.model.dropdb(input)
module.model.createdb(input)

追溯如下

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "module/models/__init__.py", line 54, in drop_db
    drop_db_with_migrations(quiet)
  File "module/models/__init__.py", line 31, in drop_db_with_migrations
    from module.app import db
  File "module/app.py", line 42, in <module>
    app.jinja_env.add_extension('hamlpy.ext.HamlPyExtension')
  File "/vagrant-dev/opt/dev_virtualenv/local/lib/python2.7/site-packages/Jinja2
-2.6-py2.7.egg/jinja2/environment.py", line 288, in add_extension
    self.extensions.update(load_extensions(self, [extension]))
  File "/vagrant-dev/opt/dev_virtualenv/local/lib/python2.7/site-packages/Jinja2
-2.6-py2.7.egg/jinja2/environment.py", line 75, in load_extensions
    extension = import_string(extension)
  File "/vagrant-dev/opt/dev_virtualenv/local/lib/python2.7/site-packages/Jinja2
-2.6-py2.7.egg/jinja2/utils.py", line 213, in import_string
    return getattr(__import__(module, None, None, [obj]), obj)
ImportError: No module named ext

1 个答案:

答案 0 :(得分:0)

您的问题出现在您的追溯中:

Traceback (most recent call last):
  -- SNIP --
  File "module/app.py", line 42, in <module>
    app.jinja_env.add_extension('hamlpy.ext.HamlPyExtension')
  -- SNIP --
ImportError: No module named ext

Jinja2使用dunder导入机制__import__(some_package_name_string)。它无法在您的ext包中找到子包hamlpy