簡體   English   中英

安裝 psycopg2 完全失敗。 巨大的錯誤消息(例如錯誤:命令 'gcc' failed with exit status 1)

[英]Installing psycopg2 fails completely. Huge error message (such as error: command 'gcc' failed with exit status 1)

我在 Mac 上安裝psycopg2時遇到問題。 我嘗試了幾種方法,例如使用pip和自制軟件安裝它。 我也下載了所有依賴項,但仍然無法安裝。

我收到以下錯誤消息,看起來很可怕:

Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/1c/nhs40gy513143dfqyblmt3r80000gn/T/pip-install-rxlPem/psycopg2/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/var/folders/1c/nhs40gy513143dfqyblmt3r80000gn/T/pip-record-93LksX/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/1c/nhs40gy513143dfqyblmt3r80000gn/T/pip-install-rxlPem/psycopg2/

可能是什么問題?

編輯:可以在此處找到完整錯誤,這似乎是最相關的部分:

clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.sdk' [-Wmissing-sysroot]
In file included from psycopg/psycopgmodule.c:27:
In file included from ./psycopg/psycopg.h:34:
/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m/Python.h:25:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
         ^~~~~~~~~
1 error generated.

psycopg2 有一些可能會給您帶來麻煩的安裝依賴項 在這種情況下,安裝過程似乎找不到stdio.h ,它是 C 標准庫的一部分。 安裝 Xcode 命令行工具可能會有所幫助。

但是,如果您不想為此煩惱,請嘗試安裝psycopg2-binary

您還可以通過從 PyPI 安裝psycopg2-binary包來獲取獨立包,不需要編譯器或外部庫:

 $ pip install psycopg2-binary

二進制包是開發和測試的實用選擇,但在生產中建議使用從源代碼構建的包。

對於任何尋求解決方案或未來參考的人,

我在 Mojave 上安裝 psycopg2 時遇到了這個問題,接下來,我可以找到 psycopg2 github問題的鏈接。 它的解決方案是安裝缺少的庫頭文件,使用

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

這可能是 Mojave 的問題,請在此處輸入鏈接描述

任何在 Debian 發行版上遇到此問題的人都可以使用此解決方案

安裝 postgresql 的開發頭文件:

sudo apt install python3-dev libpq-dev

然后嘗試:

pip3 install psycopg2

希望這能解決您的問題

暫無
暫無

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

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