I tried to follow this tutorial for customizing CKAN template but I can't seem to run the development server (paster serve /etc/ckan/default/development.ini) because of an error 'Import Error : no module named plugin'.
This is the plugin.py code (located on /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}
part of setup.py source code is like this (located on /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
''',
When I run python setup.py develop it runs succesfully.However, when I run paster server /etc/ckan/default/development.ini it results in error with message 'Import Error : No module named plugin'
I already include the plugin in development.ini file (the plugin name is example_theme)
ckan.plugins = stats text_view image_view recline_view pdf_view datastore datapusher **example_theme**
Can anybody help me with this please? where did I go wrong?
any help will be appreciated. Thanks
EDIT this is the error message :
/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
pip install -e <package_name>
– Hendrik Bunkepip install -r
not-e
.-e
is for development packages (like yours). Do you have ckanext-example_theme in/usr/lib/ckan/default/local/lib/python2.7/site-packages
? – Hendrik Bunke