昨天下午在mac上安装mysql-python一直未遂今天查了很多资料终于成功了 最后还是在stackoverflow点击打开链接(好网站啊,一般有什么技术问题在这都能找到)上找到了答案,废话少数:

首先,下载MySQLdb:http://sourceforge.net/projects/mysql-python/

下载MySQL-python-1.2.3.tar.gz

解压,运行setup.py:
python setup.py install
报错:


sh: mysql_config: command not found

Traceback (most recent call last):

  File "setup.py", line 15, in <module>

    metadata, options = get_config()

  File "/Users/***/Downloads/MySQL-python-1.2.3/setup_posix.py", line 43, in get_config

    libs = mysql_config("libs_r")

  File "/Users/***/Downloads/MySQL-python-1.2.3/setup_posix.py", line 24, in mysql_config

    raise EnvironmentError("%s not found" % (mysql_config.path,))

EnvironmentError: mysql_config not found

参考:http://www.southsearepublic.org/article/2416/read/environmenterror_mysql_config_not_found/installing_mysqldb_for_python_on_mac_osx/
发现要修改site.cfg
mysql_config = /usr/local/mysql/bin/mysql_config
让mysql_config指向mysql在mac os中的安装位置。

之后再用高权限运行
sudo python setup.py install


如果运行的时候,还有问题:
>>> import MySQLdb

/Library/Python/2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /Library/Python/2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg/_mysql.pyc, but /Users/***/Downloads/MySQL-python-1.2.3
is being added to sys.path

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "MySQLdb/__init__.py", line 19, in <module>

    import _mysql

  File "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 7, in <module>

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

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

  Referenced from: /Users/***/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so

  Reason: image not found

那么就需要解决动态引入的问题了(重新做一遍,并且设置环境变量):

$ sudo python setup.py clean

$ sudo python setup.py build

$ sudo python setup.py install

export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH

$python

>>> import MySQLdb

/Library/Python/2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /Library/Python/2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg/_mysql.pyc, but /Users/***/Downloads/MySQL-python-1.2.3
is being added to sys.path

>>> conn=MySQLdb.connect(host="localhost",user="root",passwd="root",db="mysql")

>>> cursor =conn.cursor()

>>> sql ="select * from user"

>>> cursor.execute(sql)

7L

>>> row=cursor.fetchone()

>>> print row

('localhost', 'root', '*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', '', '', '', '', 0L, 0L, 0L, 0L, '', '')

能够读取mysql.user表的信息了,说明已经mysqldb已经安装成功。

参考:http://stackoverflow.com/questions/1465846/install-mysqldb-on-snow-leopard/6537345#6537345

如果还是在eclipse中有问题,那就采用这里的办法 http://yanghao.org/blog/archives/76

解决办法: eclipse->偏好设置->Pydev->Interpreter-Python->Environment里面增加下面内容,看图:

Eclipse中配置MySQLdb模块

Window ——> Preferences ——> PyDev ——> Interpreter-Python ——> Forced Builtins ——> New... —— > 输入MySQLdb ——> OK

mac os 上安装mysqldb血泪史的更多相关文章

  1. 在Mac OS上安装Vagrant和Docker的教程

    转载于:http://www.itxuexiwang.com/a/shujukujishu/redis/2016/0216/128.html?1455808640 当听到很多人在说Docker是多么多 ...

  2. Mac OS 上安装 PostgreSQL

    PostgreSQL Database Download https://www.enterprisedb.com/downloads/postgres-postgresql-downloads 下载 ...

  3. 在 Mac OS 上使用 TypeScript 编写 ASP.NET Core 1.0 应用

    var appInsights=window.appInsights||function(config){ function r(config){t[config]=function(){var i= ...

  4. 在 mac 系统上安装 python 的 MySQLdb 模块

    在 mac 系统上安装 python 的 MySQLdb 模块 特别说明:本文主要参考了Mac系统怎么安装MySQLdb(MySQL-Python) 第 1 步:下载 MySQL-python-1.2 ...

  5. 转-在Mac OS上搭建Python的开发环境

    在Mac OS上搭建Python的开发环境   本文转载自:http://www.jb51.net/article/76931.htm 一. 安装python mac系统其实自带了一个python的执 ...

  6. Xamarin+Prism开发详解四:简单Mac OS 虚拟机安装方法与Visual Studio for Mac 初体验

    Mac OS 虚拟机安装方法 最近把自己的电脑升级了一下SSD固态硬盘,总算是有容量安装Mac 虚拟机了!经过心碎的安装探索,尝试了国内外的各种安装方法,最后在youtube上找到了一个好方法. 简单 ...

  7. 在 Mac OS 上创建并运行 ASP.NET Core 1.0 网站

    var appInsights=window.appInsights||function(config){ function r(config){t[config]=function(){var i= ...

  8. Mac OS 上设置 JAVA_HOME

    Mac OS 上设置 JAVA_HOME 原文链接:http://han.guokai.blog.163.com/blog/static/136718271201301183938165/ 由于需要, ...

  9. 在 Mac OS 上编译 FFmpeg

    本文转自:在 Mac OS 上编译 FFmpeg | www.samirchen.com 安装 Xcode 和 Command Line Tools 从 App Store 上安装 Xcode,并确保 ...

随机推荐

  1. [POJ 3311]Hie with the Pie——谈论TSP难题DP解决方法

    主题连接:  id=3311">http://poj.org/problem?id=3311 题目大意:有n+1个点,给出点0~n的每两个点之间的距离,求这个图上TSP问题的最小解 ...

  2. ORACLE union order by

    select * from ( select a.id,a.oacode,a.custid,a.custname,a.xsz,a.salename,a.communicationtheme,a.com ...

  3. measureChildren作品

    无论是在改写View依然是ViewGroup什么时候.特别ViewGrop什么时候,通常是不可避免的重写onMeasure方法,我们一定会调用setMeasuredDimension()将測量好的宽高 ...

  4. 【高德地图API】从零开始学高德JS API(七)——定位方式大揭秘

    原文:[高德地图API]从零开始学高德JS API(七)——定位方式大揭秘 摘要:关于定位,分为GPS定位和网络定位2种.GPS定位,精度较高,可达到10米,但室内不可用,且超级费电.网络定位,分为w ...

  5. 【百度地图API】如何制作班级地理通讯录?LBS通讯录

    原文:[百度地图API]如何制作班级地理通讯录?LBS通讯录 摘要:班级通讯录必备的功能,比如人员列表,人员地理位置标注,展示复杂信息窗口,公交和驾车等.一般班级人员都不会超过300个,因为可以高效地 ...

  6. exit() _exit()

    图 C程序的启动与终止 差别: _exit()函数:直接使进程停止执行,清除其使用的内存空间,并销毁其在内核中的各种数据结构; exit()函 数则在这些基础上作了一些包装,在运行退出之前加了若干道工 ...

  7. bootstrap-wysiwyg 结合 base64 解码 .net bbs 图片操作类

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Dr ...

  8. monoTouch for android visual studio c#开发

    本人  c# 程序员,第一次配置环境 按照此流程安装   http://www.wuleba.com/18892.html 本次下载的 8 个安装程序,我是安装以上顺序安装的,分别标志为1至8,暂时不 ...

  9. IOS中UIDatePicker

    UIDatePicker 1.常见属性 /* 样式 UIDatePickerModeTime,时间 UIDatePickerModeDate,日期 UIDatePickerModeDateAndTim ...

  10. 分析Cocos2d-x横版ACT手游源 2、server场景

    仍然一样 直接在代码 资源 下一个 上传 你可以看到自己 NFServerChangeLayer.h </pre><pre name="code" class=& ...