在 scrapy 管道中使用 Django 的应用程序模型会出现“应用程序尚未加载”异常
Using Django's app model in scrapy pipeline gives 'Apps aren't loaded yet' exception
我想在scrapy的pipeline.py中使用Django的(version-2.2)模型。我点击了这些链接,
并在 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?
请帮忙解决这个问题。
错误说明了您必须执行的操作。
由于您的 Django 项目配置为使用 MySQL 作为后备数据库,因此您需要在您的环境中安装 mysqlclient
包(例如 pip install mysqlclient
)重新 运行 你的 Scrapy 项目。
我想在scrapy的pipeline.py中使用Django的(version-2.2)模型。我点击了这些链接,
并在 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?
请帮忙解决这个问题。
错误说明了您必须执行的操作。
由于您的 Django 项目配置为使用 MySQL 作为后备数据库,因此您需要在您的环境中安装 mysqlclient
包(例如 pip install mysqlclient
)重新 运行 你的 Scrapy 项目。