fastkml icon indicating copy to clipboard operation
fastkml copied to clipboard

Import error Django 2.2.5

Open dennereed opened this issue 4 years ago • 1 comments

Hi there. With Python 3.7.6, Django 2.2.5, fastkml 0.11, I have an app that attempts to import fastkml in the view.py and this is raising an error. Oddly, the error does not occur on import into the Python console. For example:

Python 3.7.6 (default, Dec 30 2019, 19:38:26) [Clang 11.0.0 (clang-1100.0.33.16)] on darwin Django 2.2.5

import fastkml

No problem. But when I attempt to call it in my views.py I get error. The traceback looks like this:

Exception in thread django-main-thread: Traceback (most recent call last): File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 926, in _bootstrap_inner self.run() File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "/Users/dreed/Documents/pycharm/paleocore/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 54, in wrapper fn(*args, **kwargs) File "/Users/dreed/Documents/pycharm/paleocore/venv/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run autoreload.raise_last_exception() File "/Users/dreed/Documents/pycharm/paleocore/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 77, in raise_last_exception raise _exception[1] File "/Users/dreed/Documents/pycharm/paleocore/venv/lib/python3.7/site-packages/django/core/management/init.py", line 337, in execute autoreload.check_errors(django.setup)() File "/Users/dreed/Documents/pycharm/paleocore/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 54, in wrapper fn(*args, **kwargs) File "/Users/dreed/Documents/pycharm/paleocore/venv/lib/python3.7/site-packages/django/init.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "/Users/dreed/Documents/pycharm/paleocore/venv/lib/python3.7/site-packages/django/apps/registry.py", line 122, in populate app_config.ready() File "/Users/dreed/Documents/pycharm/paleocore/venv/lib/python3.7/site-packages/django/contrib/admin/apps.py", line 24, in ready self.module.autodiscover() File "/Users/dreed/Documents/pycharm/paleocore/venv/lib/python3.7/site-packages/django/contrib/admin/init.py", line 26, in autodiscover autodiscover_modules('admin', register_to=site) File "/Users/dreed/Documents/pycharm/paleocore/venv/lib/python3.7/site-packages/django/utils/module_loading.py", line 47, in autodiscover_modules import_module('%s.%s' % (app_config.name, module_to_search)) File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1006, in _gcd_import File "", line 983, in _find_and_load File "", line 967, in _find_and_load_unlocked File "", line 677, in _load_unlocked File "", line 728, in exec_module File "", line 219, in _call_with_frames_removed File "/Users/dreed/Documents/pycharm/paleocore/mlp/admin.py", line 10, in import mlp.views # This line raises exception! File "/Users/dreed/Documents/pycharm/paleocore/mlp/views.py", line 3, in from fastkml import kml, Placemark, Folder, Document File "/Users/dreed/Documents/pycharm/paleocore/venv/lib/python3.7/site-packages/fastkml/init.py", line 28, in from pkg_resources import get_distribution, DistributionNotFound File "/Users/dreed/Documents/pycharm/paleocore/venv/lib/python3.7/site-packages/pkg_resources/init.py", line 3250, in @_call_aside File "/Users/dreed/Documents/pycharm/paleocore/venv/lib/python3.7/site-packages/pkg_resources/init.py", line 3234, in _call_aside f(*args, **kwargs) File "/Users/dreed/Documents/pycharm/paleocore/venv/lib/python3.7/site-packages/pkg_resources/init.py", line 3263, in _initialize_master_working_set working_set = WorkingSet._build_master() File "/Users/dreed/Documents/pycharm/paleocore/venv/lib/python3.7/site-packages/pkg_resources/init.py", line 574, in _build_master ws = cls() File "/Users/dreed/Documents/pycharm/paleocore/venv/lib/python3.7/site-packages/pkg_resources/init.py", line 567, in init self.add_entry(entry) File "/Users/dreed/Documents/pycharm/paleocore/venv/lib/python3.7/site-packages/pkg_resources/init.py", line 621, in add_entry self.entry_keys.setdefault(entry, []) TypeError: unhashable type: 'Path'

dennereed avatar Mar 24 '20 05:03 dennereed

looks like the last commit on fastkml/init.py might be the source of the problem. Removing the changes from that commit, i.e. the call to pkg_resources on line 28 resolves the issue. Not sure why importing pkg_resources is creating problems.

dennereed avatar Mar 24 '20 05:03 dennereed