【问题标题】:CKAN Customize theme errorCKAN自定义主题错误
【发布时间】:2016-11-14 22:27:16
【问题描述】:

我尝试遵循 this 自定义 CKAN 模板的教程,但我似乎无法运行开发服务器(paster serve /etc/ckan/default/development.ini),因为错误“导入错误:没有名为插件的模块”。

这是 plugin.py 代码(位于 /usr/lib/ckan/default/src/ckanext-example_theme/ckanext/example_theme/plugin.py

import ckan.plugins as plugins
import ckan.plugins.toolkit as toolkit
from ckan.common import config

def show_most_popular_groups():
    value = config.get('ckan.example_theme.show_most_popular_groups',False)
    value = toolkit.asbool(value)
    return value

def most_popular_groups():
    groups = toolkit.get_action('group_list')(data_dict={'sort' : 'package_count_desc', 'all_fields' : True})
    groups = groups[0:10]

    return groups

class Example_ThemePlugin(plugins.SingletonPlugin):
    plugins.implements(plugins.IConfigurer)
    plugins.implements(plugins.ITemplateHelpers)
    # IConfigurer

def update_config(self, config_):
    toolkit.add_template_directory(config_, 'templates')
    toolkit.add_public_directory(config_, 'public')
    toolkit.add_resource('fanstatic', 'example_theme')

def get_helpers(self):
    return {'example_theme_most_popular_groups' : most_popular_groups,
            'example_theme_show_most_popular_groups' : show_most_popular_groups}

setup.py 源代码的一部分是这样的(位于/usr/lib/ckan/default/src/ckanext-example_theme/setup.py

entry_points='''
    [ckan.plugins]
    example_theme=ckanext.example_theme.plugin:Example_ThemePlugin

    [babel.extractors]
    ckan = ckan.lib.extract:extract_ckan
''',

当我运行 python setup.py develop 时,它运行成功。但是,当我运行 paster server /etc/ckan/default/development.ini 时,它会导致错误带有消息“导入错误:没有名为插件的模块

我已经在 development.ini 文件中包含了插件(插件名称是 example_theme)

ckan.plugins = stats text_view image_view recline_view pdf_view datastore datapusher **example_theme**

有人可以帮我解决这个问题吗?我哪里做错了?

任何帮助将不胜感激。谢谢

编辑 这是错误信息:

/usr/lib/ckan/default/local/lib/python2.7/site-packages/pylons/configuration.py:26: RuntimeWarning: Unable to load template engine entry point: 'pylonsmyghty = pylons.templating:MyghtyTemplatePlugin [myghty]': Traceback (most recent call last):
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/pylons/templating.py", line 610, in <module>
Engine = entry_point.load()
File "/usr/lib/ckan/default/local/lib/python2.7/site-package/pkg_resources/__init__.py", line 2228, in load
self.require(*args, **kwargs)
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2245, in require
items = working_set.resolve(reqs, env, installer)
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 808, in resolve
if not req_extras.markers_pass(req):
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 993, in markers_pass
return not req.marker or any(extra_evals) or req.marker.evaluate()
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/pkg_resources/_vendor/packaging/markers.py", line 278, in evaluate
return _evaluate_markers(self._markers, current_environment)
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/pkg_resources/_vendor/packaging/markers.py", line 203, in _evaluate_markers
lhs_value = _get_env(environment, lhs.value)
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/pkg_resources/_vendor/packaging/markers.py", line 185, in _get_env
"{0!r} does not exist in evaluation environment.".format(name)

UndefinedEnvironmentName: 'extra' does not exist in evaluation environment.

import pylons.templating
Traceback (most recent call last):
File "/usr/lib/ckan/default/bin/paster", line 11, in <module>
sys.exit(run())
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/script/command.py", line 102, in run
invoke(command, command_name, options, args[1:])
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/script/command.py", line 141, in invoke
exit_code = runner.run(args)
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/script/command.py", line 236, in run
result = self.command()
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/script/serve.py", line 284, in command
relative_to=base, global_conf=vars)
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/script/serve.py", line 329, in loadapp
**kw)
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 247, in loadapp
return loadobj(APP, uri, name=name, **kw)
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 272, in loadobj
return context.create()
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 710, in create
return self.object_type.invoke(self)
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 146, in invoke
return fix_call(context.object, context.global_conf, **context.local_conf)
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/deploy/util.py", line 55, in fix_call
val = callable(*args, **kw)
File "/home/fajarmp/ckan/lib/default/src/ckan/ckan/config/middleware/__init__.py", line 45, in make_app
load_environment(conf, app_conf)
File "/home/fajarmp/ckan/lib/default/src/ckan/ckan/config/environment.py", line 97, in load_environment
p.load_all()
File "/home/fajarmp/ckan/lib/default/src/ckan/ckan/plugins/core.py", line 139, in load_all
load(*plugins)
File "/home/fajarmp/ckan/lib/default/src/ckan/ckan/plugins/core.py", line 153, in load
service = _get_service(plugin)
File "/home/fajarmp/ckan/lib/default/src/ckan/ckan/plugins/core.py", line 255, in _get_service
return plugin.load()(name=plugin_name)
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2229, in load
return self.resolve()
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2235, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
ImportError: No module named plugin

【问题讨论】:

  • @HendrikBunke 做到了,查看编辑
  • 您是否在 virtualenv 中安装了扩展程序? pip install -e &lt;package_name&gt;
  • 你的意思是像 pip install -e requirements.txt?
  • requirements.txt 是用pip install -r 而不是-e 调用的。 -e 用于开发包(如您的)。 /usr/lib/ckan/default/local/lib/python2.7/site-packages 中有 ckanext-example_theme 吗?
  • 好吧,我在 /usr/lib/ckan/default/local/lib/python2.7/site-packages 中有这个:ckanext_example_theme-0.0.1-py2.7.egg ckanext-example-theme .egg-link 对吗?

标签: ckan


【解决方案1】:

尝试使用这些插件设置:

ckan.plugins = stats text_view recline_view example_theme
ckan.plugins = stats text_view image_view recline_view  

按顺序排列它们应该可以工作。 我注意到我以前交换过。

【讨论】:

  • 仍然产生错误。这是我的production.ini btw:ckan.plugins = stats text_view recline_view example_theme ckan.plugins = stats text_view image_view recilne_view pdf_view datastore datapusher
猜你喜欢
  • 2019-01-01
  • 1970-01-01
  • 2017-06-03
  • 2016-07-17
  • 1970-01-01
  • 2022-07-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-05
相关资源
最近更新 更多