LoginSignup
8
5

More than 5 years have passed since last update.

PyGraphvizをmacOSにインストールする

Last updated at Posted at 2018-11-04

当方はcondaではなく、pipenvを使って環境を作っている。
今回、networkxを使うために、Pygraphvizをpipでインストールしようとした時に、

pygraphviz/graphviz_wrap.c:2987:10: fatal error: 'graphviz/cgraph.h' file not found
#include "graphviz/cgraph.h"
         ^~~~~~~~~~~~~~~~~~~
1 error generated.
error: command 'clang' failed with exit status 1

などと表示されて、前に進まなかったので、備忘録としてインストール法を書き残しておく。
なお、virtualenvを使用している場合、同様の問題が起きるらしい。
ネット上に色々とやり方が載っているが、バージョンが古かったりと色々と問題があるので、こちらを参考にしてほしい。

筆者の環境

  • macOS Mojave 10.14.1
  • Python 3.7.0
  • Graphviz 2.40.1
  • PyGraphviz 1.5

インストール

Graphvizをインストール

まずHomebrewを使ってGraphvizをインストールする。


brew install graphviz

PyGraphvizをインストール

次に、pipにライブラリのインストール場所を指定してインストールをする(環境によってはインストール先が微妙に異なるかもしれない)。ここで管理者権限になっていないとエラーが起きる。

sudo  pip install --install-option="--include-path=/usr/local/include/" --install-option="--library-path=/usr/local/lib/" pygraphviz

インストール確認

最後にimportをしてみてエラーが出なければインストール完了。


Python 3.7.0 (default, Oct  2 2018, 09:18:58)
[Clang 10.0.0 (clang-1000.11.45.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygraphviz
>>>
8
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
5