【问题标题】:Getting Error trying to install MySQL-python on Mac OS X Yosemite尝试在 Mac OS X Yosemite 上安装 MySQL-python 时出错
【发布时间】:2015-10-30 04:41:20
【问题描述】:

我收到一个错误 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

【问题讨论】:

    标签: python mysql macos pip mysql-python


    【解决方案1】:

    我发现了问题,我安装了 XAMPP,XAMPP 的 mysql 使用了该标志。 我通过 Homebrew 卸载了 XAMPP 并安装了 mysql,现在一切正常。

    【讨论】:

      【解决方案2】:

      如果其他人遇到此问题并且出于某种原因不想通过更改为不同的 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 版本:2.7.10,当我使用 python setup,py install # 错误信息:你不应该直接运行它;它由 setup.py.% 使用
      【解决方案3】:

      我在使用 Softaculous AMPPS 时遇到了同样的问题。 根据 Max 的上述回复,我能够弄清楚如何解决这个问题。

      只需从“cflags”中删除“-fabi-version=2”标志(在我的例子中为第 122 行)

      【讨论】: