1

I recently experienced trouble with my hard drive and used Disk Utilities to reinstall Mac OS 10.7 Lion.
When I went to run my Django app, I got the following errors:

################ BEGIN ERRORS ##################
Traceback (most recent call last):
  File "manage.py", line 17, in <module>
    execute_manager(settings)

  File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()

  File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)

  File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)

  File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/core/management/base.py", line 209, in execute
    translation.activate('en-us')

  File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 100, in activate
    return _trans.activate(language)

  File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 202, in activate
    _active.value = translation(language)

  File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 185, in translation
    default_translation = _fetch(settings.LANGUAGE_CODE)

  File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 162, in _fetch
    app = import_module(appname)

  File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)

  File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/contrib/admin/__init__.py", line 3, in <module>
    from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME

  File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/contrib/admin/helpers.py", line 3, in <module>
    from django.contrib.admin.util import (flatten_fieldsets, lookup_field,

  File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/contrib/admin/util.py", line 1, in <module>
    from django.db import models

  File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/db/__init__.py", line 78, in <module>
    connection = connections[DEFAULT_DB_ALIAS]

  File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/db/utils.py", line 93, in __getitem__
    backend = load_backend(db['ENGINE'])

  File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/db/utils.py", line 33, in load_backend
    return import_module('.base', backend_name)

  File "/Users/my_username/Sites/python_projects/my_project/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)

  File "/Users/my_username/Sites/python_projects/my_project/lib/python2.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: No module named MySQLdb
################ END ERRORS ##################

INFO REGARDING MY DEV ENVIRONMENT:

My local dev environment uses virtualenv and virtualenvwrapper.

I checked the following from within my virtual environment (i.e. after running these commands: workon my_project; cdvirtualenv):

% which python:  /Users/my_username/Sites/python_projects/my_project/bin/python
>>> import sys
>>> sys.version
'2.7.1 (r271:86832, Jul 31 2011, 19:30:53) \n[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)]'

% which mysql:  /usr/local/mysql/bin/mysql

>>> import django
>>> django.VERSION
(1, 3, 0, 'final', 0)

I have focused my attention on reinstalling the mysql-python connector using the various recipes (e.g. http://birdhouse.org/blog/2009/09/27/python-mysql-connections-and-snow-leopard/) found on Internet. No luck. All attempts to reinstall mysql-python fail with many errors. Not sure why I would need to reinstall mysql-python anyway.

echo $PATH
-----------
/Users/my_username/Sites/python_projects/my_project/bin:/opt/subversion/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/opt/local/bin:/usr/local/git/bin:/usr/local/mysql/bin:/Developer/usr/bin


echo $PYTHONPATH
-----------------
/Users/my_username/lib/python

QUESTIONS:

  • Any tips about how to fix ?
  • Any clues about what changed/broke when I reinstalled Mac OS 10.7 ?

Any assistance appreciated. THANK YOU!

APPENDED ERROR MESSAGE WHEN ATTEMPT TO BUILD/COMPILE mysql-python:

% pwd
/Users/my_username/MySQL-python-1.2.3b2

% ARCHFLAGS='-arch x86_64' python setup.py build
--------------------------------------------------

running build

running build_py

copying MySQLdb/release.py -> build/lib.macosx-10.7-x86_64-2.7/MySQLdb

running build_ext

building '_mysql' extension

llvm-gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -pipe -Dversion_info=(1,2,3,'beta',2) -D__version__=1.2.3b2 -I/usr/local/mysql/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.7-x86_64-2.7/_mysql.o -Os -g -fno-common -fno-strict-aliasing -arch i386

In file included from _mysql.c:29:

pymemcompat.h:10:20: error: Python.h: No such file or directory

_mysql.c:30:26: error: structmember.h: No such file or directory

In file included from _mysql.c:37:

/usr/local/mysql/include/mysql.h:47:23: error: sys/types.h: No such file or directory

In file included from /usr/local/mysql/include/mysql.h:72,

                 from _mysql.c:37:

/usr/local/mysql/include/mysql_com.h:455: error: expected declaration specifiers or '...' before 'size_t'

/usr/local/mysql/include/mysql_com.h:457: error: expected declaration specifiers or '...' before 'size_t'

/usr/local/mysql/include/mysql_com.h:459: error: expected declaration specifiers or '...' before 'size_t'

/usr/local/mysql/include/mysql_com.h:460: error: expected declaration specifiers or '...' before 'size_t'

/usr/local/mysql/include/mysql_com.h:461: error: expected declaration specifiers or '...' before 'size_t'

In file included from /usr/local/mysql/include/typelib.h:20,

                 from /usr/local/mysql/include/mysql.h:131,

                 from _mysql.c:37:

/usr/local/mysql/include/my_alloc.h:44: error: expected specifier-qualifier-list before 'size_t'

_mysql.c:61: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token

_mysql.c:62: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token

_mysql.c:63: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token

[ OMITTED QUITE A NUMBER OF LINES TO PROTECT THE INNOCENT ]

_mysql.c:2533: error: expected '=', ',', ';', 'asm' or '__attribute__' before '_mysql_ConnectionObject_Type'

_mysql.c:2617: error: expected '=', ',', ';', 'asm' or '__attribute__' before '_mysql_ResultObject_Type'

_mysql.c:2703: error: expected '=', ',', ';', 'asm' or '__attribute__' before '_mysql_methods'

_mysql.c:2775: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token

_mysql.c:2807: warning: return type defaults to 'int'

_mysql.c: In function 'DL_EXPORT':

_mysql.c:2807: error: expected declaration specifiers before 'init_mysql'

_mysql.c:2885: error: expected '{' at end of input

error: command 'llvm-gcc-4.2' failed with exit status 1
Pabluez
  • 2,653
  • 3
  • 19
  • 29
chuck
  • 11
  • 2
  • It would help if you could edit your question to include the errors you get when you try to install mysql-python. See this: http://stackoverflow.com/questions/5671480/trouble-setting-up-mysqldb-module. – Nathan Jones Jan 04 '12 at 01:17
  • Thanks @NathanJones. I added the errors when attempting to install mysql-python. – chuck Jan 04 '12 at 17:49
  • I spent days on this problem and have not resolved it. From memory I did manage to get mysql-python installed using easy_install -U python-mysql but still left me with an "image not found" error when trying to use django. I know some people have succeeded though so it can be done! – PhoebeB Jan 06 '12 at 00:40

1 Answers1

0

You have two options:

  1. Manual Install
  2. Use macports

To do either of those, you need to install xcode first - available from the mac app store (free, but 4GB+ download).

Community
  • 1
  • 1
Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
  • Thanks @burhan. Before upgrade to Lion, had it working without macports. Will review manual install steps. – chuck Jan 04 '12 at 17:50