开发者社区> 问答> 正文

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

对于OSX 10.6用户,这是一个讨论很多的问题,但是我一直无法找到有效的解决方案。这是我的设置:

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

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

Traceback (most recent call last): File "manage.py", line 11, in 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 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 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 from django.db import connection File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/db/ init.py", line 75, in 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 raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e) django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb 我还安装了MySQL for Python适配器,但无济于事(也许我安装不正确?)。

有人处理过吗?

展开
收起
保持可爱mmm 2020-05-17 16:54:31 524 0
1 条回答
写回答
取消 提交回答
  • 我有同样的错误,pip install MySQL-python并为我解决了。

    备用安装:

    如果您没有点子,easy_install MySQL-python应该可以。 如果您的python是由打包系统管理的,则可能必须使用该系统(例如sudo apt-get install ...) 下面,Soli指出如果收到以下错误:

    EnvironmentError: mysql_config not found

    ...然后您还有另一个系统依赖性问题。解决方案因系统而异,但对于Debian衍生的系统:

    sudo apt-get install python-mysqldb来源:stack overflow

    2020-05-17 16:59:12
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
One Box: 解读事务与分析一体化数据库 HybridDB for MySQL 立即下载
One Box:解读事务与分析一体化数据库HybridDB for MySQL 立即下载
如何支撑HTAP场景-HybridDB for MySQL系统架构和技术演进 立即下载