我正在使用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, indjango.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 " ", 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/davea/Documents/workspace/myproject/web/models.py", line 2, in 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 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 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 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 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 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 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 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 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 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 % '", "'.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)
iraj jelodar.. 7
在Ubuntu中,您可以通过运行以下命令安装GDAL库:
sudo apt-get install gdal-bin
这解决了错误。
在Ubuntu中,您可以通过运行以下命令安装GDAL库:
sudo apt-get install gdal-bin
这解决了错误。