Файл OSX 10.8 PIP matplotlib 'freetype / config / ftheader.h' не найден

3172
fire_water

Я заранее прошу прощения, если эта тема уже обсуждалась. Моя ситуация, кажется, немного отличается от других, так что путь к моим файлам отличается. При попытке установить matplotlib в Mac OS X 10.8.5 возвращается следующая ошибка:

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 

На My 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 .

3
У меня тоже есть эта проблема. я думаю, что это было обновление до libpng, которое сломало все Zach 10 лет назад 0
+1 за сим-ссылку. Если бы эта же проблема и создание ссылки sym позволили мне установить и использовать matplotlib danengle 10 лет назад 0

1 ответ на вопрос

5
Tom Loredo

I don't think changing the contents of /usr/include (as suggested in another answer, and in other similar threads) is a good idea in general; that's Apple's "property." A similar question on StackOverflow, in the context of a Homebrew installation, instead recomments linking within /usr/local/include, which is safer, but still probably not a good idea, since Homebrew maintains that.

I think a better solution is to follow the matplotlib installation instructions and use a setup.cfg file to specify the locations of resources that aren't where it expects them. To do this while letting pip manage the installation:

  1. Download the mpl source and unpack it into DIR (e.g., DIR=matplotlib-1.3.1).

  2. cd DIR, copy 'setup.cfg.template' to 'setup.cfg', and edit the directories section to look like the following (assuming you've installed freetype2 into /usr/local, e.g., via 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/ 
  3. Build matplotlib in-place (but don't install it) via: python setup.py build_ext (takes about a minute on my MacBook Pro).

  4. Install with pip from within that directory: pip install . (note the dot!).

Pip will recognize it as matplotlib and index appropriately.

I already had mpl's dependencies installed when I did this, so I'm not sure whether missing some of them complicates this.