今天在mac电脑上安装python的mysql时出现如下问题:
该安装时是使用sudo pip install MySQL-python来安装mysql模块,安装没有问题,但是在python中导入MySQLdb的时候出现
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: dlopen(./_mysql.so, 2): no suitable image found. Did find:
./_mysql.so: mach-o, but wrong architecture
解决办法:该问题是因为mac的版本是64位的,安装的mysql和电脑版本不匹配导致的,只要设置参数如下就可以解决
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
export VERSIONER_PYTHON_PREFER_64_BIT=yes
export VERSIONER_PYTHON_PREFER_32_BIT=no
方法二:
编辑家目录下得.bash_profile文件
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
defaults write com.apple.versioner.python Prefer-32-Bit -bool no
defaults write com.apple.versioner.python Prefer-64-Bit -bool yes