安装MySQLdb遇到很大麻烦(由于32位和64位架构之间不兼容),我现在遇到了另一个奇怪的问题,我无法在网上找到解决方案。
import MySQLdb
在ipython qtconsole
中正常工作,但在ipython notebook
中则无效。在后者中,我收到以下错误:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-dd22983d5391> in <module>()
----> 1 import MySQLdb
/Users/username/anaconda/lib/python2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.5-x86_64.egg/MySQLdb/__init__.py in <module>()
17 from MySQLdb.release import __version__, version_info, __author__
18
---> 19 import _mysql
20
21 if version_info != _mysql.version_info:
ImportError: dlopen(/Users/username/anaconda/lib/python2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.5-x86_64.egg/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Users/username/anaconda/lib/python2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.5-x86_64.egg/_mysql.so
Reason: image not found
libmysqlclient.18.dylib
位于$DYLD_LIBRARY_PATH
。
例如:$echo $DYLD_LIBRARY_PATH
返回
:/usr/local/mysql/lib/:/usr/local/mysql/lib/
我是如何解决此问题的,或者这是ipython notebook
错误。
答案 0 :(得分:0)
这是一个老问题,但万一其他人正在努力安装MySQLdb ...
有一个名为“pymysql”的纯python mysql驱动程序。您通常可以将其用作MySQLdb的替代品。它安装起来要容易得多,因为它不需要任何二进制文件。
此处有更多详情:What is PyMySQL and how does it differ from MySQLdb? Can it affect Django deployment?