gpt4 book ai didi

python - Django 中的 MySQLdb 错误

转载 作者:行者123 更新时间:2023-11-29 21:31:37 26 4
gpt4 key购买 nike

我完全迷失了,无法找到问题的解决方案。我启动了 virtualenv 并使用 python 版本 2.7 在其中安装了最新版本的 django。然后我按照 django 教程进行操作,但我没有在开发服务器上工作,而是使用了 apache2 localhost,一切都工作正常。然后为了检查 mysql 支持,我更改了设置文件并安装了 mysqlclient 并使用了 python manage.py makemigrations ,然后使用了 python manage.py migrate一切顺利。最后我重新启动apache,出现500 Internal Server Error。我现在提供 apache 错误日志和我的设置文件。

[Thu Feb 04 11:24:13.190280 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] Traceback (most recent call last):
[Thu Feb 04 11:24:13.190504 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] File "/home/kapil/work/database/roadrunner/roadrunner/wsgi.py", line 16, in <module>
[Thu Feb 04 11:24:13.190516 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] application = get_wsgi_application()
[Thu Feb 04 11:24:13.190711 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] File "/home/kapil/work/database/roadrunner/roadrunnerground/lib/python2.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[Thu Feb 04 11:24:13.190724 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] django.setup()
[Thu Feb 04 11:24:13.190925 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] File "/home/kapil/work/database/roadrunner/roadrunnerground/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
[Thu Feb 04 11:24:13.190938 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] apps.populate(settings.INSTALLED_APPS)
[Thu Feb 04 11:24:13.191272 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] File "/home/kapil/work/database/roadrunner/roadrunnerground/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
[Thu Feb 04 11:24:13.191288 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] app_config.import_models(all_models)
[Thu Feb 04 11:24:13.191620 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] File "/home/kapil/work/database/roadrunner/roadrunnerground/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
[Thu Feb 04 11:24:13.191641 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] self.models_module = import_module(models_module_name)
[Thu Feb 04 11:24:13.191934 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] File "/usr/lib/python3.4/importlib/__init__.py", line 109, in import_module
[Thu Feb 04 11:24:13.191949 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] return _bootstrap._gcd_import(name[level:], package, level)
[Thu Feb 04 11:24:13.192004 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
[Thu Feb 04 11:24:13.192043 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
[Thu Feb 04 11:24:13.192083 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
[Thu Feb 04 11:24:13.192123 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
[Thu Feb 04 11:24:13.192162 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] File "<frozen importlib._bootstrap>", line 1129, in _exec
[Thu Feb 04 11:24:13.192201 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] File "<frozen importlib._bootstrap>", line 1471, in exec_module
[Thu Feb 04 11:24:13.192241 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
[Thu Feb 04 11:24:13.192456 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] File "/home/kapil/work/database/roadrunner/runner/models.py", line 4, in <module>
[Thu Feb 04 11:24:13.192469 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] class Question(models.Model):
[Thu Feb 04 11:24:13.193404 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] File "/home/kapil/work/database/roadrunner/roadrunnerground/lib/python2.7/site-packages/django/db/models/base.py", line 108, in __new__
[Thu Feb 04 11:24:13.193436 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] new_class.add_to_class('_meta', Options(meta, app_label))
[Thu Feb 04 11:24:13.193520 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] File "/home/kapil/work/database/roadrunner/roadrunnerground/lib/python2.7/site-packages/django/db/models/base.py", line 299, in add_to_class
[Thu Feb 04 11:24:13.193532 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] value.contribute_to_class(cls, name)
[Thu Feb 04 11:24:13.194132 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] File "/home/kapil/work/database/roadrunner/roadrunnerground/lib/python2.7/site-packages/django/db/models/options.py", line 263, in contribute_to_class
[Thu Feb 04 11:24:13.194165 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
[Thu Feb 04 11:24:13.194409 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] File "/home/kapil/work/database/roadrunner/roadrunnerground/lib/python2.7/site-packages/django/db/__init__.py", line 36, in __getattr__
[Thu Feb 04 11:24:13.194424 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] return getattr(connections[DEFAULT_DB_ALIAS], item)
[Thu Feb 04 11:24:13.194730 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] File "/home/kapil/work/database/roadrunner/roadrunnerground/lib/python2.7/site-packages/django/db/utils.py", line 212, in __getitem__
[Thu Feb 04 11:24:13.194745 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] backend = load_backend(db['ENGINE'])
[Thu Feb 04 11:24:13.194807 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] File "/home/kapil/work/database/roadrunner/roadrunnerground/lib/python2.7/site-packages/django/db/utils.py", line 116, in load_backend
[Thu Feb 04 11:24:13.194818 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] return import_module('%s.base' % backend_name)
[Thu Feb 04 11:24:13.194876 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] File "/usr/lib/python3.4/importlib/__init__.py", line 109, in import_module
[Thu Feb 04 11:24:13.194887 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] return _bootstrap._gcd_import(name[level:], package, level)
[Thu Feb 04 11:24:13.194927 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
[Thu Feb 04 11:24:13.194966 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
[Thu Feb 04 11:24:13.195005 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
[Thu Feb 04 11:24:13.195045 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
[Thu Feb 04 11:24:13.195084 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] File "<frozen importlib._bootstrap>", line 1129, in _exec
[Thu Feb 04 11:24:13.195123 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] File "<frozen importlib._bootstrap>", line 1471, in exec_module
[Thu Feb 04 11:24:13.195163 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
[Thu Feb 04 11:24:13.195234 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] File "/home/kapil/work/database/roadrunner/roadrunnerground/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 28, in <module>
[Thu Feb 04 11:24:13.195245 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
[Thu Feb 04 11:24:13.195297 2016] [:error] [pid 23833] [remote 127.0.0.1:25140] django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: /home/kapil/work/database/roadrunner/roadrunnerground/lib/python2.7/site-packages/_mysql.so: undefined symbol: _Py_ZeroStruct

这是有关数据库配置的settings.py内容。

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'roadrunner',
'USER': 'root',
'PASSWORD': 'kapilgarg',
'HOST': 'localhost',
}
}

从apache错误日志的最后一行,它指向_mysql.so: undefined symbol ,似乎存在一些链接问题或版本不匹配问题。有人可以帮我吗?我们将不胜感激。

最佳答案

在虚拟环境中安装模块

pip install MySQL-python

关于python - Django 中的 MySQLdb 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35206855/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com