pythondjangotastypie

Problem when import ModelResource from tastypie.resources


I am new to Django and I want to create some API with tastypie, but when I import ModelResource from tastypie.resource I face with error :/ I just do this:

from tastypie.resources import ModelResource

I get this error:

Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 954, in _bootstrap_inner
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/macbook/.local/share/virtualenvs/PriceList-ofEay4QN/lib/python3.9/site-packages/django/utils/autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "/Users/macbook/.local/share/virtualenvs/PriceList-ofEay4QN/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 110, in inner_run
    autoreload.raise_last_exception()
  File "/Users/macbook/.local/share/virtualenvs/PriceList-ofEay4QN/lib/python3.9/site-packages/django/utils/autoreload.py", line 87, in raise_last_exception
    raise _exception[1]
  File "/Users/macbook/.local/share/virtualenvs/PriceList-ofEay4QN/lib/python3.9/site-packages/django/core/management/__init__.py", line 375, in execute
    autoreload.check_errors(django.setup)()
  File "/Users/macbook/.local/share/virtualenvs/PriceList-ofEay4QN/lib/python3.9/site-packages/django/utils/autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "/Users/macbook/.local/share/virtualenvs/PriceList-ofEay4QN/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/macbook/.local/share/virtualenvs/PriceList-ofEay4QN/lib/python3.9/site-packages/django/apps/registry.py", line 114, in populate
    app_config.import_models()
  File "/Users/macbook/.local/share/virtualenvs/PriceList-ofEay4QN/lib/python3.9/site-packages/django/apps/config.py", line 301, in import_models
    self.models_module = import_module(models_module_name)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/Users/macbook/Documents/PriceList/api/models.py", line 4, in <module>
    from tastypie.resources import ModelResource
  File "/Users/macbook/.local/share/virtualenvs/PriceList-ofEay4QN/lib/python3.9/site-packages/tastypie/resources.py", line 22, in <module>
    from django.contrib.gis.db.models.fields import GeometryField
  File "/Users/macbook/.local/share/virtualenvs/PriceList-ofEay4QN/lib/python3.9/site-packages/django/contrib/gis/db/models/__init__.py", line 3, in <module>
    import django.contrib.gis.db.models.functions  # NOQA
  File "/Users/macbook/.local/share/virtualenvs/PriceList-ofEay4QN/lib/python3.9/site-packages/django/contrib/gis/db/models/functions.py", line 3, in <module>
    from django.contrib.gis.db.models.fields import BaseSpatialField, GeometryField
  File "/Users/macbook/.local/share/virtualenvs/PriceList-ofEay4QN/lib/python3.9/site-packages/django/contrib/gis/db/models/fields.py", line 3, in <module>
    from django.contrib.gis import forms, gdal
  File "/Users/macbook/.local/share/virtualenvs/PriceList-ofEay4QN/lib/python3.9/site-packages/django/contrib/gis/forms/__init__.py", line 3, in <module>
    from .fields import (  # NOQA
  File "/Users/macbook/.local/share/virtualenvs/PriceList-ofEay4QN/lib/python3.9/site-packages/django/contrib/gis/forms/fields.py", line 2, in <module>
    from django.contrib.gis.gdal import GDALException
  File "/Users/macbook/.local/share/virtualenvs/PriceList-ofEay4QN/lib/python3.9/site-packages/django/contrib/gis/gdal/__init__.py", line 28, in <module>
    from django.contrib.gis.gdal.datasource import DataSource
  File "/Users/macbook/.local/share/virtualenvs/PriceList-ofEay4QN/lib/python3.9/site-packages/django/contrib/gis/gdal/datasource.py", line 40, in <module>
    from django.contrib.gis.gdal.driver import Driver
  File "/Users/macbook/.local/share/virtualenvs/PriceList-ofEay4QN/lib/python3.9/site-packages/django/contrib/gis/gdal/driver.py", line 5, in <module>
    from django.contrib.gis.gdal.prototypes import ds as vcapi, raster as rcapi
  File "/Users/macbook/.local/share/virtualenvs/PriceList-ofEay4QN/lib/python3.9/site-packages/django/contrib/gis/gdal/prototypes/ds.py", line 9, in <module>
    from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal
  File "/Users/macbook/.local/share/virtualenvs/PriceList-ofEay4QN/lib/python3.9/site-packages/django/contrib/gis/gdal/libgdal.py", line 50, in <module>
    lgdal = CDLL(lib_path)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(/usr/local/lib/libgdal.dylib, 6): Symbol not found: _curl_multi_poll
  Referenced from: /usr/local/lib/libgdal.dylib
  Expected in: /usr/lib/libcurl.4.dylib
 in /usr/local/lib/libgdal.dylib

The current Django version is 3.2 . I try to install the latest version of Django (4.1.1) to fix the error but it doesn't work. The version of tastypie is 0.14.4. If it helps I use python version 3.9. Thanks


Solution

  • Problem solved :/ There was a problem with GDAL on my system and the Django version. I just run this command in my terminal:

    brew link --overwrite gdal
    

    and downgrade the Django version to 3.2 .