欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 运维知识 > 数据库 >内容正文

数据库

python在mac上运行不用装模块_MAC OSX使用Python安装mysql模块问题

发布时间:2025/3/15 数据库 53 豆豆
生活随笔 收集整理的这篇文章主要介绍了 python在mac上运行不用装模块_MAC OSX使用Python安装mysql模块问题 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

系统环境:MAC OSX 10.9.2

Python版本:2.7.5

新入手的RMBP,自带了Python环境,但是将其投入到生产环境时,出现了种种问题,首先最最致命的,就是安装模块出现问题,导致一直无法正常开发,下面是本人在安装Python模块的时候,所出现并解决的,总结如下,希望对后来者有帮助(拿MySQL-python举例,安装PIL也遇到了同样的问题):

(1)不管在使用easy_install安装模块,还是下载安装包,使用sudo python setup.py build安装,都会出现:

******

error: command 'cc' failed with exit status 1

clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]

clang: note: this will be a hard error (cannot be downgraded to a warning) in the future

error: command 'cc' failed with exit status 1

经过一系列的查找:http://www.tuicool.com/articles/zI7Vzu,貌似是MAC OS的Xcode从5.1起给编译器规定对于未知参数传入视为error,我们需要使用ARCHFLAGS将该error降级为warning,因此最后的安装命令应该如下:

sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future easy_install MySQL-python

这样,问题就解决了,成功安装上了MySQL-python

(2)虽然安装上了MySQL-python,在代码开发过程中,运行代码,问题又出现了:

******

import MySQLdb

File "build/bdist.macosx-10.9-intel/egg/MySQLdb/__init__.py", line 19, in

File "build/bdist.macosx-10.9-intel/egg/_mysql.py", line 7, in

File "build/bdist.macosx-10.9-intel/egg/_mysql.py", line 6, in __bootstrap__

ImportError: dlopen(/Users/kris/.python-eggs/MySQL_python-1.2.5-py2.7-macosx-10.9-intel.egg-tmp/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib

Referenced from: /Users/kris/.python-eggs/MySQL_python-1.2.5-py2.7-macosx-10.9-intel.egg-tmp/_mysql.so

Reason: image not found

经过查找,我添加两个符号链接(软链接):

sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql

再次运行程序,问题就解决了。

总结

以上是生活随笔为你收集整理的python在mac上运行不用装模块_MAC OSX使用Python安装mysql模块问题的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。