python mac下安装 MySQLdb模块的坑

尝试了brew install和pip install最终还是用了最原始的办法解决:

 在SourceForge可以下载MySQL-python-1.2.4b4.tar (或者 https://pypi.python.org/pypi/MySQL-python/1.2.4b4),下载后解压,然后在终端Terminal中执行以下命令:

pip install MySQL-python

如果提示:

mysql_config not found

解决办法:
在MySQL-python的安装包中找到site.cfg文件,打开它,找到以下内容:
# The path to mysql_config. # Only use this if mysql_config is not on your PATH, or you have some weird # setup that requires it. # #mysql_config = /usr/local/bin/mysql_config

把mysql_config改为正确的路径

即可。

下面是坑。

_mysql.c:1504:11: warning: implicit conversion loses integer precision:
      ‘unsigned long’ to ‘int’ [-Wshorten-64-to-32]
                                len = strlen(buf);
                                    ~ ^~~~~~~~~~~
_mysql.c:1506:11: warning: implicit conversion loses integer precision:
      ‘unsigned long’ to ‘int’ [-Wshorten-64-to-32]
                                len = strlen(buf);
                                    ~ ^~~~~~~~~~~
13 warnings generated.
cc -bundle -undefined dynamic_lookup -Wl,-F. build/temp.macosx-10.14-intel-2.7/_mysql.o -L/usr/local/Cellar/mysql/8.0.18/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.14-intel-2.7/_mysql.so
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command ‘cc’ failed with exit status 1

解决办法:

安装的时候没有引用这个链接,然后继续访问下面那个哥们留的那个地址,关于类似问题的解决方案:

http://stackoverflow.com/questions/26288042/error-installing-psycopg2-library-not-found-for-lssl/39244687#39244687

这篇文章里有类似这样的话

you could also try to link against brew’s openssl:

env LDFLAGS=”-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib”pip install psycopg2

到这里,我心里大概有点明白了,我执行安装的时候,需要把openssl/lib的路径链接上去,我去找了下openssl路径,确实是/usr/local/opt/openssl/lib/,而且里面确实有 libssl.a和libssl.dylib两个文件。

然后 执行

env LDFLAGS=”-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib” python setup.py install

安装成功!

转载随意~:陶醉seo » python mac下安装 MySQLdb模块的坑

赞 (0)
分享到:更多 ()