Python:MySQLdb和“库未加载:libmysqlclient.16.dylib”

2024-05-19 12:24:32 发布

您现在位置:Python中文网/ 问答频道 /正文

设置

尝试安装一个干净的macosx10.6来开发python/django,我不记得在10.5上遇到过这个。

mysql-5.5.8-osx10.6-x86_64.dmg上从安装程序安装MySQL之后,我运行

$ sudo pip install MySQL-python

看起来进展顺利(下面是输出)

Downloading/unpacking MySQL-python
  Downloading MySQL-python-1.2.3.tar.gz (70Kb): 70Kb downloaded
  Running setup.py egg_info for package MySQL-python
    warning: no files found matching 'MANIFEST'
    warning: no files found matching 'ChangeLog'
    warning: no files found matching 'GPL'
Installing collected packages: MySQL-python
  Running setup.py install for MySQL-python
    building '_mysql' extension
    gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -pipe -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/local/mysql/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c _mysql.c -o build/temp.macosx-10.6-universal-2.6/_mysql.o -Os -g -fno-common -fno-strict-aliasing -arch x86_64
    In file included from _mysql.c:36:
    /usr/local/mysql/include/my_config.h:325:1: warning: "SIZEOF_SIZE_T" redefined
    In file included from /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h:9,
                     from pymemcompat.h:10,
                     from _mysql.c:29:
    /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/pymacconfig.h:33:1: warning: this is the location of the previous definition
    In file included from _mysql.c:36:
    /usr/local/mysql/include/my_config.h:419:1: warning: "HAVE_WCSCOLL" redefined
    In file included from /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h:8,
                     from pymemcompat.h:10,
                     from _mysql.c:29:
    /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/pyconfig.h:803:1: warning: this is the location of the previous definition
    gcc-4.2 -Wl,-F. -bundle -undefined dynamic_lookup build/temp.macosx-10.6-universal-2.6/_mysql.o -L/usr/local/mysql/lib -lmysqlclient_r -lpthread -o build/lib.macosx-10.6-universal-2.6/_mysql.so -arch x86_64
    warning: no files found matching 'MANIFEST'
    warning: no files found matching 'ChangeLog'
    warning: no files found matching 'GPL'
Successfully installed MySQL-python
Cleaning up...

之后我试着:

$ python -c "import MySQLdb"

然后我就被:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Library/Python/2.6/site-packages/MySQLdb/__init__.py", line 19, in <module>
    import _mysql
ImportError: dlopen(/Library/Python/2.6/site-packages/_mysql.so, 2): Library not loaded: libmysqlclient.16.dylib
  Referenced from: /Library/Python/2.6/site-packages/_mysql.so
  Reason: image not found

所以我的问题是

我做错了什么?/我还需要做什么?

google(并在这里搜索)会返回很多结果,用Ruby得到这个错误消息,用Python得到的结果不多。


Tags: nofromincludepackageslibrarymysqlframeworkfiles
3条回答

_mysql.so指的是libmysqlclient.16.dylib。也就是说,充当Python和MySQL客户机库之间的桥梁的共享库_mysql.so是MySQL客户机库的动态库,由于某种原因无法加载该库。

你需要回答的问题:

  • 你的系统上有什么地方吗?如果没有,您需要安装 MySQL客户端软件。
  • 如果是,那么包含该库的目录是否在您的DYLD_LIBRARY_PATH设置中?如果不是, 尝试添加它。
  • 如果是,则必须确保libmysqlclient.16.dylib文件没有损坏。我的 副本,安装在/opt/local/lib/mysql5/mysql/libmysqlclient.16.dylib中,由提供 MacPorts有MD5签名c79ee91af08057dfc269ee212915801a,大小为1462376字节。你的副本是什么样的?

只要在运行pip installeasy_install之后设置DYLD_LIBRARY_PATH

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

假设您的MySQL安装位于/usr/local/mysql下,就可以完成这项工作。

在简单安装之后,我创建了一个解决问题的软链接

sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib

相关问题 更多 >