gpt4 book ai didi

Python 导入 MySQLdb 错误 - Mac 10.6

转载 作者:IT王子 更新时间:2023-10-28 23:44:59 25 4
gpt4 key购买 nike

我下载并遵循了 MySQL 5.5.8 ( http://dev.mysql.com/downloads/mysql/ ) 和 MySQLdb python 插件的安装说明。 ( http://sourceforge.net/projects/mysql-python/ )

当我尝试将 MySQLdb 导入 python 终端时,出现以下错误:

Safira:~ yanigisawa$ python --version
Python 2.6.1
Safira:~ yanigisawa$ python -c "import MySQLdb"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "build/bdist.macosx-10.6-universal/egg/MySQLdb/__init__.py", line 19, in <module>
File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 7, in <module>
File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/yanigisawa/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so, 2): Library not loaded: libmysqlclient.16.dylib
Referenced from: /Users/yanigisawa/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so
Reason: image not found
Safira:~ yanigisawa$

我找到了问题 4559699在堆栈溢出时,并按照那里的说明进行操作:

Safira:~ yanigisawa$ echo $DYLD_LIBRARY_PATH
/usr/local/mysql/lib
Safira:~ yanigisawa$ ls -l /usr/local/mysql/lib
total 363224
-rwxr-xr-x 1 root wheel 3787328 Jan 18 19:41 libmysqlclient.16.dylib
-rw-r--r-- 1 root wheel 10035336 Dec 3 13:26 libmysqlclient.a
lrwxr-xr-x 1 root wheel 23 Jan 14 22:01 libmysqlclient.dylib -> libmysqlclient.16.dylib
lrwxr-xr-x 1 root wheel 20 Jan 14 22:01 libmysqlclient_r.16.dylib -> libmysqlclient.dylib
lrwxr-xr-x 1 root wheel 16 Jan 14 22:01 libmysqlclient_r.a -> libmysqlclient.a
lrwxr-xr-x 1 root wheel 20 Jan 14 22:01 libmysqlclient_r.dylib -> libmysqlclient.dylib
-rw-r--r-- 1 root wheel 88033760 Dec 3 13:22 libmysqld-debug.a
-rw-r--r-- 1 root wheel 84075304 Dec 3 13:26 libmysqld.a
-rw-r--r-- 1 root wheel 8472 Dec 3 13:26 libmysqlservices.a
drwxr-xr-x 13 root wheel 442 Dec 3 13:53 plugin
Safira:~ yanigisawa$ md5 /usr/local/mysql/lib/libmysqlclient.16.dylib
MD5 (/usr/local/mysql/lib/libmysqlclient.16.dylib) = b8a78a93183720021b9dbe9ddad57111
Safira:~ yanigisawa$

在清除所有 python egg 文件并重建后,我仍然遇到同样的错误。然后我在影响 Mac 10.6 的 MySQL 5.5.8 中发现了错误 59006 ( http://bugs.mysql.com/bug.php?id=59006 )。我尝试了那里列出的变通方法,清理鸡蛋并重建,但我仍然收到此错误。

对于这个特定于 python 的问题,是否有另一种解决方法?我还缺少其他东西吗?

编辑:添加 otool 命令的输出:

Safira:~ yanigisawa$ otool -L /Users/yanigisawa/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so
/Users/yanigisawa/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so:
libmysqlclient.16.dylib (compatibility version 16.0.0, current version 16.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.1)
Safira:~ yanigisawa$ otool -DX /usr/local/mysql/lib/libmysqlclient.16.dylib
/usr/local/mysql/lib/libmysqlclient.16.dylib
Safira:~ yanigisawa$

最佳答案

就我而言,我通过添加几个符号链接(symbolic link)来解决问题,如 http://ageekstory.blogspot.com/2011/04/installing-massive-coupon-on-mac-os-10.html

如下:

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

sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql

关于Python 导入 MySQLdb 错误 - Mac 10.6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4730787/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com