web-dev-qa-db-ja.com

PyCharmテストの実行時に「Django.core.exceptions.ImproperlyConfigured:GDALライブラリが見つかりませんでした」を解決するにはどうすればよいですか?

私はDjango、Python 3.7とPyCharm 2018.3.5を使用しています。このテストファイルがあります...

./web/tests/view_tests.py

以下のようになります

# Basic test to verify we can get valid return data
def test_calculate_tax(self):
    state = 'MN'
    gross = 100000
    salary = 75000
    json_data = json.dumps({'state': state,
                            'gross': gross,
                            'salary': salary})

    response = c.post('/content/vote/', json_data,
                      content_type='application/json',
                      HTTP_X_REQUESTED_WITH='XMLHttpRequest')
    self.assertEqual(response.status_code, 302)  # this is OK.
    print(response.content)
    self.assertEqual(response.content, 2)

PyCharmでテスト名を右クリックして[テストの実行]オプションを選択すると、以下のエラーが発生します。私はそれが何を意味するのか、それを修正する方法がわかりません...

Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/helpers/pycharm/Django_test_manage.py", line 56, in <module>
    Django.setup()
  File "/Users/davea/Documents/workspace/myproject/venv/lib/python3.7/site-packages/Django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/davea/Documents/workspace/myproject/venv/lib/python3.7/site-packages/Django/apps/registry.py", line 114, in populate
    app_config.import_models()
  File "/Users/davea/Documents/workspace/myproject/venv/lib/python3.7/site-packages/Django/apps/config.py", line 211, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/local/Cellar/python/3.7.2_2/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 "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/davea/Documents/workspace/myproject/web/models.py", line 2, in <module>
    from Django.contrib.gis.db import models
  File "/Users/davea/Documents/workspace/myproject/venv/lib/python3.7/site-packages/Django/contrib/gis/db/models/__init__.py", line 3, in <module>
    import Django.contrib.gis.db.models.functions  # NOQA
  File "/Users/davea/Documents/workspace/myproject/venv/lib/python3.7/site-packages/Django/contrib/gis/db/models/functions.py", line 4, in <module>
    from Django.contrib.gis.db.models.fields import BaseSpatialField, GeometryField
  File "/Users/davea/Documents/workspace/myproject/venv/lib/python3.7/site-packages/Django/contrib/gis/db/models/fields.py", line 3, in <module>
    from Django.contrib.gis import forms, gdal
  File "/Users/davea/Documents/workspace/myproject/venv/lib/python3.7/site-packages/Django/contrib/gis/forms/__init__.py", line 3, in <module>
    from .fields import (  # NOQA
  File "/Users/davea/Documents/workspace/myproject/venv/lib/python3.7/site-packages/Django/contrib/gis/forms/fields.py", line 2, in <module>
    from Django.contrib.gis.gdal import GDALException
  File "/Users/davea/Documents/workspace/myproject/venv/lib/python3.7/site-packages/Django/contrib/gis/gdal/__init__.py", line 28, in <module>
    from Django.contrib.gis.gdal.datasource import DataSource
  File "/Users/davea/Documents/workspace/myproject/venv/lib/python3.7/site-packages/Django/contrib/gis/gdal/datasource.py", line 39, in <module>
    from Django.contrib.gis.gdal.driver import Driver
  File "/Users/davea/Documents/workspace/myproject/venv/lib/python3.7/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/davea/Documents/workspace/myproject/venv/lib/python3.7/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/davea/Documents/workspace/myproject/venv/lib/python3.7/site-packages/Django/contrib/gis/gdal/libgdal.py", line 43, in <module>
    % '", "'.join(lib_names)
Django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal", "GDAL", "gdal2.3.0", "gdal2.2.0", "gdal2.1.0", "gdal2.0.0", "gdal1.11.0"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.

これを理解するための助けがいただければ幸いです。

編集: これは、USStateFieldをモデルフィールドとして含めようとしたことによる副作用の可能性があると思いますか?下記参照。私はこれを行う他の方法を受け入れます。

from localflavor.us.models import USStateField
...
class UsLocation(models.Model):
    address_1 = models.CharField(_("address"), max_length=128)
    address_2 = models.CharField(_("address cont'd"), max_length=128, blank=True)

    city = models.CharField(_("city"), max_length=64, null=False)
    state = USStateField(_("state"), null=False)
    Zip_code = models.CharField(_("Zip code"), max_length=10, null=False)
5
Dave

チェックアウト this ページ。一部の人がこの問題を抱えているようで、パッケージを再インストールするか、自作で再インストールする必要がありました。

0
Hybrid