gpt4 book ai didi

python - 如何在 OSX 10.6 中将 MySQLdb 与 Python 和 Django 一起使用?

转载 作者:IT老高 更新时间:2023-10-28 12:10:35 25 4
gpt4 key购买 nike

对于 OSX 10.6 用户来说,这是一个备受争议的问题,但我一直无法找到可行的解决方案。这是我的设置:

Python 2.6.1 64 位Django 1.2.1MySQL 5.1.47 osx10.6 64bit

我使用 --no-site-packages 创建了一个 virtualenvwrapper,然后安装了 Django。当我激活 virtualenv 并运行 python manage.py syncdb 时,我得到了这个错误:

Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/core/management/__init__.py", line 257, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/core/management/__init__.py", line 67, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/core/management/commands/syncdb.py", line 7, in <module>
from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/core/management/sql.py", line 5, in <module>
from django.contrib.contenttypes import generic
File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/contrib/contenttypes/generic.py", line 6, in <module>
from django.db import connection
File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/db/__init__.py", line 75, in <module>
connection = connections[DEFAULT_DB_ALIAS]
File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/db/utils.py", line 91, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/db/utils.py", line 32, in load_backend
return import_module('.base', backend_name)
File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/db/backends/mysql/base.py", line 14, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

我还安装了 MySQL for Python适配器,但无济于事(也许我安装不正确?)。

以前有人处理过吗?

最佳答案

我遇到了同样的错误,pip install MySQL-python 帮我解决了。

备用安装:

  • 如果你没有 pip,easy_install MySQL-python 应该可以工作。
  • 如果您的 python 由打包系统管理,您可能必须使用该系统(例如 sudo apt-get install ...)

下面,Soli 指出,如果您收到以下错误:

EnvironmentError: mysql_config not found

...那么您还有一个系统依赖性问题。解决这个问题会因系统而异,但对于 Debian 派生系统:

sudo apt-get install python-mysqldb

关于python - 如何在 OSX 10.6 中将 MySQLdb 与 Python 和 Django 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2952187/

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