
如果這個話題已經被討論過,我先道歉。我的情況似乎與其他人略有不同,因此我的文件的路徑不同。嘗試在 Mac OS X 10.8.5 上安裝 matplotlib 時,傳回下列錯誤:
pip install matplotlib
# lots of install details here...
/usr/X11/include/ft2build.h:56:10: fatal error: 'freetype/config/ftheader.h' file not found
#include <freetype/config/ftheader.h>
^
1 error generated.
error: command 'clang' failed with exit status 1
----------------------------------------
Cleaning up...
Command /usr/bin/python -c "import setuptools, tokenize;__file__='/private/tmp/pip_build_root/matplotlib/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-ohMPzS-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /private/tmp/pip_build_root/matplotlib
Storing debug log for failure in /Users/administrator/Library/Logs/pip.log
我的 Homebrew 安裝了以下內容:
fontconfig
gfortran
jpeg
libtiff
pkg-config
freetype
libpng
我正在使用 Mac 版本的 Python 2.7.2,位於 /usr/bin/python
所以我使用 Finder 搜尋 ftheader.h,它說該檔案位於:
/opt/X11/include/freetype2/freetype/config/ftheader.h
我的問題是:
- matplotlib 是否在錯誤的位置尋找 ftheader.h?
- 如果是這樣,我如何告訴它在正確的位置找到?
- 或者,有其他原因導致了問題?
謝謝你!
更新:
這似乎已經解決了問題:
sudo ln -s /usr/local/include/freetype2/ /usr/include/freetype
這會建立一個從/usr/include/freetype 到/usr/local/include/freetype2/ 的符號連結(當您點擊/usr/include/freetype 時,您將被重定向到/usr/local/include/ freetype2/ )。在建立符號連結之前,最好先驗證系統上的第一個路徑是否正確。如果第二條路徑不存在,則將建立它。
建立符號連結後,我sudo pip install matplotlib
再次嘗試,這次安裝成功。 Mucho 道具這個帖子為了這個想法!如果下游出現錯誤,我會回報。
還值得注意的是,matplotlib 二進位文件存在。
答案1
我不認為更改 /usr/include 的內容(如另一個答案和其他類似線程中所建議的)一般來說不是一個好主意;那是蘋果的「財產」。一個相似的關於 StackOverflow 的問題,在 Homebrew 安裝的上下文中,建議在 /usr/local/include 內鏈接,這更安全,但仍然可能不是一個好主意,因為 Homebrew 維護了這一點。
我認為更好的解決方案是遵循 matplotlib 安裝說明並使用 setup.cfg 檔案來指定不在預期位置的資源位置。若要在讓 pip 管理安裝的同時執行此操作:
下載 mpl 來源並將其解壓縮到 DIR(例如,DIR=matplotlib-1.3.1)。
cd DIR
,將“setup.cfg.template”複製到“setup.cfg”,然後編輯目錄部分,如下所示(假設您已將 freetype2 安裝到 /usr/local 中,例如透過 Homebrew):[directories] # Uncomment to override the default basedir in setupext.py. # This can be a single directory or a comma-delimited list of directories. #basedirlist = /usr basedirlist = /usr/local/include/freetype2/
透過以下方式就地建立 matplotlib(但不安裝):(
python setup.py build_ext
在我的 MacBook Pro 上大約需要一分鐘)。從該目錄使用 pip 安裝:(
pip install .
注意點!)。
Pip 會將其識別為 matplotlib 並適當索引。
當我這樣做時,我已經安裝了 mpl 的依賴項,所以我不確定缺少其中一些依賴項是否會使情況變得複雜。