mod_wsgi cannot load mysql
Question: First I will list my environment and status:

Environment:

  * System: Mac OS 10.6
  * Python: 2.6
  * Apache: 2.2
  * mod_wsgi: 3.3
  * mysql: 5.x
  * php: 3.5
  * trac:0.12

Status: I can run trac as alone-server without problem. Now I integrate trac
to apache, problem come out. mod_wsgi can run normal wsgi page correctly, but
cannot load mysql connection. I test it in piece of code, put "**import
MySQLdb** " in wsgi page, it still cannot. I also can access trac through
apache, but it shows me **Cannot load Python bindings for MySQL**

I refer to the apache log:

    
    
    [Sun Mar 13 13:36:44 2011] [error] [client ::1] mod_wsgi (pid=37060): Target WSGI script /Users/alex/Library/apache2/htdocs/sql.wsgi' cannot be loaded as Python module.
    
    [Sun Mar 13 13:36:44 2011] [error] [client ::1] mod_wsgi (pid=37060): Exception occurred processing WSGI script '/Users/alex/Library/apache2/htdocs/sql.wsgi'.
    
    [Sun Mar 13 13:36:44 2011] [error] [client ::1] Traceback (most recent call last):
    
    [Sun Mar 13 13:36:44 2011] [error] [client ::1]   File "/Users/alex/Library/apache2/htdocs/sql.wsgi", line 2, in <module>
    
    [Sun Mar 13 13:36:44 2011] [error] [client ::1]     import MySQLdb
    
    [Sun Mar 13 13:36:44 2011] [error] [client ::1]   File "build/bdist.macosx-10.6-universal/egg/MySQLdb/__init__.py", line 19, in <module>
    
    [Sun Mar 13 13:36:44 2011] [error] [client ::1]   File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 7, in <module>
    
    [Sun Mar 13 13:36:44 2011] [error] [client ::1]   File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 6, in __bootstrap__
    
    [Sun Mar 13 13:36:44 2011] [error] [client ::1] ImportError: dlopen(/Users/alex/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so, 2): Library not loaded: libmysqlclient.16.dylib
    
    [Sun Mar 13 13:36:44 2011] [error] [client ::1]   Referenced from: /Users/alex/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so
    
    [Sun Mar 13 13:36:44 2011] [error] [client ::1]   Reason: image not found
    
    [Sun Mar 13 13:36:57 2011] [error] [client ::1] mod_wsgi (pid=37061): Target WSGI script
    

This looks like mod_wsgi cannot find libmysqlclient.16.dylib. I encounter
similar problem when I install mysqldb for python, so I add export

`DYLD_LIBRARY_PATH=/Users/alex/Library/mysql-5.x/lib`

SO python -c "import MySQLdb" can work, but mod_wsgi cannot work. So I put

    
    
    os.environ['DYLD_LIBRARY_PATH'] = '/Users/alex/Library/mysql-5.x/lib'
    

into trac.ini. It doesn't work for trac in apache still.

So anyone has this problem before? Thanks


Answer: Try **LD_LIBRARY_PATH** instead:

    
    
    export LD_LIBRARY_PATH=/usr/local/mysql/lib/mysql:$LD_LIBRARY_PATH
    

