簡體   English   中英

命令'cc'在OSX High Sierra上以退出狀態1失敗

[英]command 'cc' failed with exit status 1 on OSX High Sierra

我正試圖在Mac Os高山上運行

pip install MySQL-python

但我得到了

error: command 'cc' failed with exit status 1

我已經嘗試過關於這個主題的解決方案,但它沒有用。

這是完整的錯誤消息

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/

這是python

which python
/usr/bin/python

這就是我正在使用的點子

which pip
/usr/local/bin/pip

首先,你確定要使用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的軟件包,而是使用install-as-MySQLdb選項構建的mysqlclient 因此,如果您嘗試使用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不支持它們,但是它們可能有用 - Oracle仍然為那些提供Mac二進制安裝程序。 如果在主下載部分找不到它們,則鏡像的“下載”文件夾將包含它們。 截至目前,5.6和5.7具有以-macos10.13-x86_64.dmg結尾的二進制安裝程序包。

但是,您可能更樂意使用Homebrew安裝它。 按照該頁面上的說明安裝brew ,然后將其用於:

brew install mysql@5.5

MySQL-python 需要OpenSSL庫,而Apple故意隱藏操作系統使用的那些庫,以防止人們意外地針對舊版本構建代碼而不獲取安全更新。 較新的庫應該都知道如何處理這個,但MySQL-python沒有。 安裝可用OpenSSL的最簡單方法是再次使用Homebrew:

brew install openssl

但是,不要只運行該命令並關閉窗口。 閱讀輸出,因為如果你想構建MySQL-python,你必須完成它所說的所有內容。

阿巴梅特的回答對我不起作用。 雖然這樣做,但您可以嘗試跳過第一步,

brew install mysql-connector-c
brew install mysql
brew link --overwrite mysql
pip install MySQL-python

我的問題是我使用的是MySql版本8.0.12。 一旦我降級到MySQL 5.7,它就完美安裝了。 我使用以下內容刪除版本8: https//gist.github.com/vitorbritto/0555879fe4414d18569d

上述要點是:

  1. 使用以下命令檢查MySQL進程:ps -ax | grep mysql
  2. 停止並終止任何MySQL進程
  3. brew刪除mysql
  4. 釀造清理
  5. launchctl unload -w~ / Library / LaunchAgents / homebrew.mxcl.mysql.plist
  6. sudo rm / usr / local / mysql
  7. sudo rm -rf / usr / local / var / mysql
  8. sudo rm -rf / usr / local / mysql *
  9. sudo rm~ / Library / LaunchAgents / homebrew.mxcl.mysql.plist
  10. sudo rm -rf / Library / StartupItems / MySQLCOM
  11. sudo rm -rf / Library / PreferencePanes / My *
  12. rm -rf~ / Library / PreferencePanes / My *
  13. sudo rm -rf / Library / Receipts / mysql *
  14. sudo rm -rf / Library / Receipts / MySQL *
  15. sudo rm -rf / private / var / db / receipts / mysql
  16. 重新啟動計算機只是為了確保任何MySQL進程都被終止
  17. 使用brew安裝mysql:brew install mysql@5.7
  18. 最后,pip install mysql-python

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM