或者
问答详情页顶部banner图
您的位置:首页 >推广 > 其他 > 其他 > Mac系统怎么安装MySQLdb

Mac系统怎么安装MySQLdb

提问者:神马浮云  |   分类:其他  |   浏览224次  |   悬赏分:1积分 2017-06-24 09:56:34

我要回答

提 交

匿名

  • 李小白SEO

    下载MySQLdb   在SourceForge可以下载MySQL-python-1.2.4b4.tar,下载后解压,然后在终端Terminal中执行以下命令: new-host-3:~ iFantastic$ cd /Users/iFantastic/Downloads/MySQL-python-1.2.4b4 new-host-3:MySQL-python-1.2.4b4 iFantastic$ python setup.py install  使用pip安装MySQLdb   在终端中执行: new-host-3:~ iFantastic$ pip install MySQL-python   无论是在线安装还是下载安装,此时你可能会遇到第一个错误提示: EnvironmentError: mysql_config not found   建议使用pip安装,因为我从sourceforge下载的版本居然不如pip中的新。如果想要升级mysql-python版本,可以使用以下命令: $ easy_install MySQL-python --upgrade   [注意]如果你没有按照下文解决安装中的错误提示,那么升级也会因为同样的错误原因而失败。  解决mysql_config not found错误   在默认方式安装Mac版MySql时,会在/usr/local/mysql/bin目录下生成mysql_config文件。   因此下载安装时的解决办法为:在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 = /usr/local/mysql/bin/mysql_config   然后执行: $ python setup.py install   一般说来,此时安装可以完成,但仍有问题,下文会继续阐述。   使用pip安装时没有办法修改site.cfg文件,因此可以通过修改OS X的系统环境变量来解决找不到mysql_config的错误。   修改OS X环境变量:打开终端,在终端中使用vim打开“~/.bash_profile”,如果没有安装vim,那就显示隐藏文件用文本编辑器打开,具体操作这里就不复述了。在.bash_profile中添加以下内容: PATH="/usr/local/mysql/bin:${PATH}" export PATH export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/ export VERSIONER_PYTHON_PREFER_64_BIT=no export VERSIONER_PYTHON_PREFER_32_BIT=yes   其中 VERSIONER_PYTHON_PREFER_64_BIT和VERSIONER_PYTHON_PREFER_64_BIT根据自己安装的MySQL进行选择。   另外再提供一个pip安装时找不到mysql_config的解决方法(我没有验证),在终端中输入以下命令: $ sudo ln -s /usr/local/mysql/bin/* /usr/bin   好了,到这里,MySQL-python包应该基本顺利安装。  解决 Reason: image not found 错误   安装完MySQL-python包后,让我们import MySQLdb,此时出现一个错误,错误最后一行写着 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 错误: 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

    2017-06-26 11:45:45
    评论0  |   0
问答详情中间banner