2

I have macbook pro running OS X 10.7 on Intel processor. I have installed Django 1.3.1, MySQL-python 1.2.3. All the packages installed fine. When I execute command "python manage.py sql poll", I'm running into the following exception.

Traceback (most recent call last):
  File "manage.py", line 14, in <module>
    execute_manager(settings)
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 67, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/Library/Python/2.7/site-packages/django/core/management/commands/sql.py", line 4, in <module>
    from django.core.management.sql import sql_create
  File "/Library/Python/2.7/site-packages/django/core/management/sql.py", line 6, in <module>
    from django.db import models
  File "/Library/Python/2.7/site-packages/django/db/__init__.py", line 78, in <module>
    connection = connections[DEFAULT_DB_ALIAS]
  File "/Library/Python/2.7/site-packages/django/db/utils.py", line 93, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/Library/Python/2.7/site-packages/django/db/utils.py", line 33, in load_backend
    return import_module('.base', backend_name)
  File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/Library/Python/2.7/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/khoa/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so, 2): no suitable image found.  Did find:
    /Users/khoa/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so: mach-o, but wrong architecture
Ned Deily
  • 83,389
  • 16
  • 128
  • 151
Kevin
  • 304
  • 3
  • 14
  • Check this answer: http://stackoverflow.com/questions/3061277/python-mysql-wrong-architecture-error/7552035#7552035 – DS. Dec 17 '11 at 06:06

1 Answers1

2

Chances are that the Python you are using (the Apple-supplied Python 2.7.1, perhaps) is running in 64-bit mode but the MySQLdb extension module that you've installed is 32-bit only. Or, possibly, the reverse. The output of this shell command should tell you what architectures the extension module was compiled for:

file /Users/khoa/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so

The MySQLdb extension module and the MySQL client libraries you've installed must have a common architecture with the architecture that the Python instance you are using.

Ned Deily
  • 83,389
  • 16
  • 128
  • 151
  • It looks like they are both Mach-O bundle i386. – Kevin Dec 17 '11 at 08:15
  • file /Users/khoa/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so /Users/khoa/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so: Mach-O bundle i386 file python /Users/khoa/Sites/env/foobar/bin/python: Mach-O universal binary with 2 architectures /Users/khoa/Sites/env/foobar/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64 /Users/khoa/Sites/env/foobar/bin/python (for architecture i386): Mach-O executable i386 – Kevin Dec 17 '11 at 08:18
  • I'm not sure what else to try. I followed the instructions here(http://hackercodex.com/2011/08/30/python-install-django-on-mac-osx-lion-10.7/) but still running into the same problem. – Kevin Dec 17 '11 at 08:19
  • What version of the MySQL client libraries did you install? Try running `file` on the dependencies listed by running `otool -L ` on the `_mysql.so` file and see what archs are there. There are many ways you can run into problems when you pick and choose components from different sources. My recommendation when trying to install and run Django with MySQL on OS X is to use a complete solution from MacPorts. Despite the poster's advocating Homebrew over MacPorts, it's hard to beat the MacPorts one-liner: `sudo port install py27-django py27-mysql`. And it actually works. – Ned Deily Dec 17 '11 at 10:11
  • I did what you suggested. sudo port install py27-django py27-mysql but I still run into the same issue. – Kevin Dec 17 '11 at 19:55
  • (foobar)kevin-vos-macbook-pro:project khoa$ otool -L /Users/khoa/sites/env/foobar/lib/python2.7/site-packages/_mysql.so /Users/khoa/sites/env/foobar/lib/python2.7/site-packages/_mysql.so: /usr/local/mysql/lib/libmysqlclient_r.16.dylib (compatibility version 17.0.0, current version 17.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0) – Kevin Dec 17 '11 at 19:55
  • Is it because of /usr/lib/libSystem.B.dylib? Do I need to downgrade it? – Kevin Dec 17 '11 at 19:56
  • Don't touch anything in `/usr/lib`! Everything there is part of OS X and managed by Apple. No, the problem is undoubtedly with the version of the MySQL client libraries you installed there in `/usr/local/mysql/lib/libmysqlclient_r.16.dylib`. If you do a `file` on the library you'll probably find that it is only 32-bit. You need to not use the MySQLdb egg that you installed. The easiest way should be to ensure you are running with the MacPorts-installed Django. Either create a new Django project using /opt/local/django-admin-2.7.py and copy your old source files or alter the paths. – Ned Deily Dec 17 '11 at 20:32
  • You should also consider removing the old MySQL rooted at `/usr/local/mysql5' and associated files in `/usr/local/bin`. That can cause problems with some packages that look there first. – Ned Deily Dec 17 '11 at 20:33