命令'cc'在OSX High Sierra上以退出状态1失败

Fil*_*ano 4 python macos mysql-python python-2.7

我正试图在Mac Os高山上运行

pip install MySQL-python
Run Code Online (Sandbox Code Playgroud)

但我得到了

error: command 'cc' failed with exit status 1
Run Code Online (Sandbox Code Playgroud)

我已经尝试过关于这个主题的解决方案,但它没有用.

这是完整的错误消息

The directory '/Users/filipeferminiano/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/filipeferminiano/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting MySQL-python
  Downloading https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip (108kB)
    100% |????????????????????????????????| 112kB 289kB/s 
Installing collected packages: MySQL-python
  Running setup.py install for MySQL-python ... error
    Complete output from command /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-install-8I1X5u/MySQL-python/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/tmp/pip-record-z5HohX/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.13-intel-2.7
    copying _mysql_exceptions.py -> build/lib.macosx-10.13-intel-2.7
    creating build/lib.macosx-10.13-intel-2.7/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb
    copying MySQLdb/converters.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb
    copying MySQLdb/connections.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb
    copying MySQLdb/release.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb
    copying MySQLdb/times.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb
    creating build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
    running build_ext
    building '_mysql' extension
    creating build/temp.macosx-10.13-intel-2.7
    cc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/Cellar/mysql/8.0.11/include/mysql -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.13-intel-2.7/_mysql.o
    _mysql.c:44:10: fatal error: 'my_config.h' file not found
    #include "my_config.h"
             ^~~~~~~~~~~~~
    1 error generated.
    error: command 'cc' failed with exit status 1

    ----------------------------------------
Command "/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-install-8I1X5u/MySQL-python/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/tmp/pip-record-z5HohX/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/tmp/pip-install-8I1X5u/MySQL-python/
Run Code Online (Sandbox Code Playgroud)

这是python

which python
/usr/bin/python
Run Code Online (Sandbox Code Playgroud)

这是我正在使用的点子

which pip
/usr/local/bin/pip
Run Code Online (Sandbox Code Playgroud)

aba*_*ert 7

首先,你确定要使用MySQL-python吗?这是一个在过去五年中为遗留支持进行半维护的大部分死亡项目,甚至不适用于当前版本的MySQL.它想要5.0或​​5.1; 当前版本是8.0,甚至当前的旧版本是5.7.


其他选择包括:

  • mysql-connector,又名MySQLConnector/Python:这是MySQL/Oracle官方支持的库.它可能有点慢,这对大多数项目来说无关紧要,但有时也可以.它也有一个不同的API(虽然如果你坚持使用DB-API 2方法,唯一的区别是连接调用;除此之外它应该只是低级别的东西,这是不同的).
  • mysqlclient:这是Django和其他一些框架使用的包.这是一个更新的分支MySQL-Python(有一些来自其废弃的继任者moist).它甚至可以配置为自己安装MySQLdb,使用相同的名称MySQL-python.
  • PyMySQL:第三方软件包,尽可能与旧版本兼容,MySQL-python但更简单,更易于维护和安装.
  • cmysql,它的分叉PyMySQL只是稍微难以安装,但应该比它快,或者比它快mysql-connector.

一些Linux发行版 - 包括IIRC,Ubuntu的最新版本 - 提供了一个名为python-MySQLdb或类似的包,实际上并不是MySQL-python,而是mysqlclient使用install-as-MySQLdb选项构建的.所以,如果您尝试使用的唯一原因MySQL-python是它是您在某些Ubuntu盒子上使用的,那么它可能不是您使用的,因此不是您想要的.

其中一些替代方案也需要MySQL(特别是MySQLConnector/C,又名libmysqlclient,及其开发库),有些则不需要- 但它们都与当前版本兼容.(虽然有关于在文档中进行PyMySQL和cmysql,你可能想,如果你使用8.0阅读8.0加密变化的一些注意事项.)


无论如何,如果你真的想要MySQL-python,那么你需要在5.x版本中安装MySQL.INSTALL下载MySQL的要点.

如果你想要5.0或​​5.1,你将需要挖掘Downloads其中一个镜像的文件夹来查找源包并按照说明构建和安装它,因为没有二进制安装程序可以在当前的Mac上运行.

如果您想以后5.x版本,其中,记住,不是由MySQL-python的支持,但他们可能会奏效,甲骨文仍然是为那些Mac的二进制安装程序.如果在主下载部分找不到它们,则镜像的"下载"文件夹将包含它们.截至目前,5.6和5.7具有以二进制结束的二进制安装程序包-macos10.13-x86_64.dmg.

但是,您可能更乐意使用Homebrew安装它.按照该页面上的说明进行安装brew,然后将其用于:

brew install mysql@5.5
Run Code Online (Sandbox Code Playgroud)

MySQL-python 需要OpenSSL库,而Apple故意隐藏操作系统使用的那些库,以防止人们意外地针对旧版本构建代码而不获取安全更新.较新的库应该都知道如何处理这个,但MySQL-python没有.安装可用OpenSSL的最简单方法是再次使用Homebrew:

brew install openssl
Run Code Online (Sandbox Code Playgroud)

但是,不要只运行该命令并关闭窗口.阅读输出,因为如果你想构建MySQL-python,你必须完成它所说的所有内容.


Opt*_*ime 0

阿巴默特的回答对我不起作用。虽然这样做了,但您可以尝试跳过第一步,

brew install mysql-connector-c
brew install mysql
brew link --overwrite mysql
pip install MySQL-python
Run Code Online (Sandbox Code Playgroud)