在Scrapy管道中使用Django的应用程序模型会导致“应用程序尚未加载”异常

时间:2018-08-02 13:11:17

标签: django django-models web-scraping scrapy scrapy-pipeline

我想在scrapy的pipe.py中使用Django的(version-2.2)模型。我点击了这些链接,

  1. https://medium.com/@ali_oguzhan/how-to-use-scrapy-with-django-application-c16fabd0e62e
  2. Use Django's models in a Scrapy project (in the pipeline)

并在scrpay项目的settings.py中添加了行“ django.setup()”。 它给了我以下错误,

File "D:\Technologies\Python_Code\django_develops\django_development\kumo_soft\findchipsData\..\inventory\models.py", line 7, in <module>
  class Product(models.Model):
File "c:\program files (x86)\lib\site-packages\django-2.2-py3.6.egg\django\db\models\base.py", line 101, in _new_
  new_class.add_to_class('_meta', Options(meta, app_label))
File "c:\program files (x86)\lib\site-packages\django-2.2-py3.6.egg\django\db\models\base.py", line 304, in add_to_class
  value.contribute_to_class(cls, name)
File "c:\program files (x86)\lib\site-packages\django-2.2-py3.6.egg\django\db\models\options.py", line 203, in contribute_to_class
  self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "c:\program files (x86)\lib\site-packages\django-2.2-py3.6.egg\django\db\__init_.py", line 33, in _getattr_
  return getattr(connections[DEFAULT_DB_ALIAS], item)
File "c:\program files (x86)\lib\site-packages\django-2.2-py3.6.egg\django\db\utils.py", line 202, in _getitem_
  backend = load_backend(db['ENGINE'])
File "c:\program files (x86)\lib\site-packages\django-2.2-py3.6.egg\django\db\utils.py", line 110, in load_backend
  return import_module('%s.base' % backend_name)
File "c:\program files (x86)\lib\importlib\__init_.py", line 126, in import_module
  return bootstrap.gcd_import(name[level:], package, level)
File "c:\program files (x86)\lib\site-packages\django-2.2-py3.6.egg\django\db\backends\mysql\base.py", line 20, in <module>
  ) from err
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?

请帮助解决此问题。

1 个答案:

答案 0 :(得分:0)

该错误表明您必须执行的操作。

由于Django项目已配置为将MySQL用作后备数据库,因此您需要在运行Scrapy项目的环境中安装mysqlclient软件包(例如pip install mysqlclient)。