ckan / ckanapi

A command line interface and Python module for accessing the CKAN Action API
Other
176 stars 74 forks source link

Import errors using python3 #131

Closed luispedro18 closed 6 years ago

luispedro18 commented 6 years ago

Hi!

I want to use the python module of ckanapi but I need to use it with python3. When I import ckanapi in my py file (e.g: import ckanapi) I get this error

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/tenant/__main__.py", line 8, in <module>
    from data_exporters import e
  File "/tenant/data_exporters/__init__.py", line 7, in <module>
    module = loader.find_module(name).load_module(name)
  File "/tenant/data_exporters/ckan.py", line 11, in <module>
    from ckanapi import RemoteCKAN
  File "/usr/local/lib/python3.6/site-packages/ckanapi/__init__.py", line 8, in <module>
    from ckanapi.errors import (
  File "/usr/local/lib/python3.6/site-packages/ckanapi/errors.py", line 63, in <module>
    from ckan.logic import (NotAuthorized, NotFound, ValidationError)
ModuleNotFoundError: No module named 'ckan.logic'; 'ckan' is not a package

Anyone knows why doest it happen?

wardi commented 6 years ago

you might a directory called ckan (so import ckan "works") that isn't actually a copy of ckan. We can catch ModuleNotFound error as well as ImportError to fix this edge case

luispedro18 commented 6 years ago

I don't have any directory called ckan but the file where I'm importing the module is called ckan.py. Does it matter?

wardi commented 6 years ago

if your current directory is in your python path then it will matter. Try renaming your module.

luispedro18 commented 6 years ago

I've renamed the module and it works now. Thanks a lot, you saved my day!!

TkTech commented 6 years ago

Would recommend against catching ModuleNotFound, the exception is working exactly as expected and the error message is clear.