我是 mac 和 python 的新手。我已经为 python mac 安装了 mysqldb。但是当我尝试导入它时,这是我得到的错误:
Traceback (most recent call last):
File "<stdin>", 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): Symbol not found: _strnlen
Referenced from: /usr/lib/libmysqlclient.18.dylib
Expected in: /usr/lib/libSystem.B.dylib
in /usr/lib/libmysqlclient.18.dylib
为什么我会收到这个错误?我该如何解决?我已经尝试了很多关于 SO 的答案,但似乎没有任何效果。我应该怎么做才能解决此错误?
谢谢。
最佳答案
你安装的时候有没有使用sudo
?
sudo pip install mysql-python
然后将这一行添加到您的 ~/.bash_profile
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
关于python - 无法在 mac 上的 python 中导入 mysqldb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19012418/