MySQLdb problems in django

元气小坏坏 提交于 2020-01-03 02:20:07

问题


I installed mysql-python on 64bit snow leopard,and it's good under python IDE,but failed import in django. Anyone had meet similar question?

File "/Library/Python/2.6/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/szanlin/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so, 
2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Users/szanlin/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so
Reason: image not found

回答1:


I had the same problem and I was able to find the answer here:

http://www.curlybrace.com/words/2011/01/25/mac-os-mysql-python-1-2-3-importerror-library-not-loaded-libmysqlclient-16-dylib/

Basically you need to add this line:

export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/

to your /etc/bashrc file.

Another page that was helpful can be found here:

http://programmingzen.com/2007/12/22/how-to-install-django-with-mysql-on-mac-os-x/




回答2:


Just the clarify the above answer. Great answer and PowerAnimal is correct. If I could vote him up I would.

Please add the line:

export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/

to:

user/.bash_profile

This is a hidden file. You can view this file by using the following command in terminal.

defaults write com.apple.Finder AppleShowAllFiles YES

then:

killall Finder

When finished:

defaults write com.apple.Finder AppleShowAllFiles NO

then:

killall Finder

To check that Python is communicating with MySQL:

import MySQLdb

MySQLdb.apilevel

To check that Django is working:

import django

print django.VERSION

If no errors, you should be able to continue with your Django setup.



来源:https://stackoverflow.com/questions/7109731/mysqldb-problems-in-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!