Django + OsX Lion + Mysql与XAMPP

时间:2011-09-04 21:30:44

标签: python mysql django mysql-python osx-lion

我在MacBook上使用Osx Lion时有以下内容:

  • 使用xampp运行的Mysql(http://www.apachefriends.org/it/xampp.html)
  • Django 1.3在virtualenv中运行

我用pip install MySQL-python

安装了Mysql-python

但是在尝试使用manage.py syncdb时出现以下错误:

(django_1.3)Daniel-Mac:fz_biblio daniel$ python manage.py syncdb
Traceback (most recent call last):
  File "manage.py", line 14, in <module>
    execute_manager(settings)
  File "/Users/daniel/Sites/django-proj/virtual-env/django_1.3/lib/python2.5/site-packages/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/Users/daniel/Sites/django-proj/virtual-env/django_1.3/lib/python2.5/site-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/daniel/Sites/django-proj/virtual-env/django_1.3/lib/python2.5/site-packages/django/core/management/__init__.py", line 261, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/Users/daniel/Sites/django-proj/virtual-env/django_1.3/lib/python2.5/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/daniel/Sites/django-proj/virtual-env/django_1.3/lib/python2.5/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/Users/daniel/Sites/django-proj/virtual-env/django_1.3/lib/python2.5/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/daniel/Sites/django-proj/virtual-env/django_1.3/lib/python2.5/site-packages/django/core/management/sql.py", line 6, in <module>
    from django.db import models
  File "/Users/daniel/Sites/django-proj/virtual-env/django_1.3/lib/python2.5/site-packages/django/db/__init__.py", line 78, in <module>
    connection = connections[DEFAULT_DB_ALIAS]
  File "/Users/daniel/Sites/django-proj/virtual-env/django_1.3/lib/python2.5/site-packages/django/db/utils.py", line 93, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/Users/daniel/Sites/django-proj/virtual-env/django_1.3/lib/python2.5/site-packages/django/db/utils.py", line 33, in load_backend
    return import_module('.base', backend_name)
  File "/Users/daniel/Sites/django-proj/virtual-env/django_1.3/lib/python2.5/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/Users/daniel/Sites/django-proj/virtual-env/django_1.3/lib/python2.5/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: dlopen(/Users/daniel/.python-eggs/MySQL_python-1.2.3-py2.5-macosx-10.7-i386.egg-tmp/_mysql.so, 2): no suitable image found.  Did find:
        /Users/daniel/.python-eggs/MySQL_python-1.2.3-py2.5-macosx-10.7-i386.egg-tmp/_mysql.so: mach-o, but wrong architecture
(django_1.3)Daniel-Mac:fz_biblio daniel$ mate "/Users/daniel/Sites/django-proj/virtual-env/django_1.3/lib/python2.5/site-packages/django/db/backends/mysql/base.py
> "
(django_1.3)Daniel-Mac:fz_biblio daniel$ mate /Users/daniel/Sites/django-proj/virtual-env/django_1.3/lib/python2.5/site-packages/django/db/backends/mysql/base.py

为了让django在我的环境中使用mysql,有什么想法吗?!?!

2 个答案:

答案 0 :(得分:0)

此问题与XAMPP无关。您无法使用MySQL-python安装pip install。我建议使用homebrew,它可以正确安装。

另见:

mysql-python installation problems (on mac os x lion)

virtualenv pip mysqldb mac os X python

答案 1 :(得分:0)

我终于解决了为我的机器安装正确版本的MySQL的问题。

我安装了MySQL 64bit版本 - &gt; Mac OS X ver. 10.6 (x86, 64-bit)

安装完毕后一切正常。我想这是因为我以前的安装是一个32位的,这就是为什么mysql-python抱怨错误的架构。