python - 尝试在 Mac OS X Yosemite 上安装 MySQL-python 时出错

标签 python mysql macos pip mysql-python

我收到一个错误 clang: error: unknown argument: '-fabi-version=2' 当我尝试使用 pip 安装 mysql-python 时。

MacBook-Pro-de-Haruan:MySQL-python-1.2.5 haruan$ sudo -E pip install MySQL-python
The directory '/Users/haruan/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/haruan/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting MySQL-python
  Downloading MySQL-python-1.2.5.zip (108kB)
    100% |████████████████████████████████| 110kB 311kB/s 
Installing collected packages: MySQL-python
  Running setup.py install for MySQL-python
    Complete output from command /usr/local/opt/python/bin/python2.7 -c "import setuptools, tokenize;__file__='/private/var/folders/sh/gl953xl12p3fl1k0lkw10_k00000gn/T/pip-build-ZBmISy/MySQL-python/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/sh/gl953xl12p3fl1k0lkw10_k00000gn/T/pip-5RkJ0a-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.10-x86_64-2.7
    copying _mysql_exceptions.py -> build/lib.macosx-10.10-x86_64-2.7
    creating build/lib.macosx-10.10-x86_64-2.7/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.macosx-10.10-x86_64-2.7/MySQLdb
    copying MySQLdb/converters.py -> build/lib.macosx-10.10-x86_64-2.7/MySQLdb
    copying MySQLdb/connections.py -> build/lib.macosx-10.10-x86_64-2.7/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.macosx-10.10-x86_64-2.7/MySQLdb
    copying MySQLdb/release.py -> build/lib.macosx-10.10-x86_64-2.7/MySQLdb
    copying MySQLdb/times.py -> build/lib.macosx-10.10-x86_64-2.7/MySQLdb
    creating build/lib.macosx-10.10-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.10-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.macosx-10.10-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.10-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.macosx-10.10-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.10-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.10-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.10-x86_64-2.7/MySQLdb/constants
    running build_ext
    building '_mysql' extension
    creating build/temp.macosx-10.10-x86_64-2.7
    clang -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Qunused-arguments -Qunused-arguments -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/Applications/XAMPP/xamppfiles/include -I/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.10-x86_64-2.7/_mysql.o -arch x86_64 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing
    clang: error: unknown argument: '-fabi-version=2'
    error: command 'clang' failed with exit status 1

    ----------------------------------------
Command "/usr/local/opt/python/bin/python2.7 -c "import setuptools, tokenize;__file__='/private/var/folders/sh/gl953xl12p3fl1k0lkw10_k00000gn/T/pip-build-ZBmISy/MySQL-python/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/sh/gl953xl12p3fl1k0lkw10_k00000gn/T/pip-5RkJ0a-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/sh/gl953xl12p3fl1k0lkw10_k00000gn/T/pip-build-ZBmISy/MySQL-python

我已经用过:

export CFLAGS=-Qunused-arguments
export CPPFLAGS=-Qunused-arguments
export ARCHFLAGS='-Wno-error=unused-command-line-argument-hard-error-in-future'

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

sudo -E ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip mysql-python

问题仍然存在。

我的 Xcode 是版本 6.4 (6E35b) 我正在使用 Mac OS X Yosemite

最佳答案

如果其他人遇到此问题并且出于某种原因不想通过更改为不同的 MySQL 安装来解决它,则有一个相对简单的解决方法。我在尝试针对 Bitnami MAMP 堆栈 5.5 版中包含的 MySQL 包编译 mysqlclient 时遇到了这个问题。您只需要调整安装,这样有问题的参数就不会传递给编译器,如下所示:

  1. GitHub下载包
  2. 打开 setup_posix.py 文件
  3. extra_compile_args 变量初始化后(当前版本第 58-59 行),添加以下代码行:extra_compile_args.pop(extra_compile_args.index('-fabi-version =2'))
  4. 在包目录下,运行python setup.py install

为我工作。

关于python - 尝试在 Mac OS X Yosemite 上安装 MySQL-python 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31865818/

相关文章:

php - iOS、PHP 和 mySQL。在 iPhone 上显示数据库中的数据

macos - 如何使用 osx 终端删除目录中文件夹名称为 X 的所有文件夹

python - 为什么需要 'b' 来使用 Base64 编码字符串?

python - Django self.cleaned_data Keyerror

python - 在 Python 中将复杂的键(元组)存储到 JSON 中

mysql - 运行 php index.php 控制台迁移后出错

mysql - 从表 A 中获取项目,该表通过表 B 链接到表 C。三重联接?

xcode - 获取 NSTextField 的 keyDown 事件

macos - biopython 安装测试失败 : ERROR: test_fetch_xml_schemas (test_Entrez_online. EntrezOnlineCase)

python - 如何为 GitPython 设置默认分支