不能在ipython笔记本中使用/导入MySQLdb(在ipython qtconsole中运行良好)

时间:2012-12-24 16:43:38

标签: python ipython mysql-python ipython-notebook

安装MySQLdb遇到很大麻烦(由于32位和64位架构之间不兼容),我现在遇到了另一个奇怪的问题,我无法在网上找到解决方案。

import MySQLdbipython 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错误。

1 个答案:

答案 0 :(得分:0)

这是一个老问题,但万一其他人正在努力安装MySQLdb ...

有一个名为“pymysql”的纯python mysql驱动程序。您通常可以将其用作MySQLdb的替代品。它安装起来要容易得多,因为它不需要任何二进制文件。

此处有更多详情:What is PyMySQL and how does it differ from MySQLdb? Can it affect Django deployment?