[python] Macにpygraphvizをインストールする
Django-extentionsにはモデルをグラフィカルに表示できる機能があると耳にして、実際にやってみたら、pygraphviz
をインストールする際につまづいたのでメモ。
環境
OS: Mac OS Mojave 10.14.3
python: pyenv python3.7.1
モデルをグラフィカルに表示する
メモの本題ではないので、軽く済ませますがDjango-extentionsにはモデルをグラフィカルに表示するコマンドがあり、以下のように実行します。
python manage.py graph_models -a -g -o graph-model.png
CommandError: Neither pygraphviz nor pydotplus could be found to generate the image. To generate text output, use the --json or --dot options.
実行してみたところpygraphviz
とpydotplus
というパッケージが足りないと言われたのでインストール
pygraphvizとpydotplusをインストール
pip install pygraphviz pydotplus
Running setup.py install for pygraphviz ... error
Complete output from command /Users/username/.pyenv/versions/3.7.1/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/pq/s_dm6c0d183642pp933rkcqm0000gn/T/pip-install-8w4_fiaf/pygraphviz/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/pq/s_dm6c0d183642pp933rkcqm0000gn/T/pip-record-fag39uff/install-record.txt --single-version-externally-managed --compile:
running install
Trying dpkg
Failed to find dpkg
Trying pkg-config
Package libcgraph was not found in the pkg-config search path.
Perhaps you should add the directory containing `libcgraph.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libcgraph' found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/pq/s_dm6c0d183642pp933rkcqm0000gn/T/pip-install-8w4_fiaf/pygraphviz/setup.py", line 93, in <module>
tests_require=['nose>=1.3.7', 'doctest-ignore-unicode>=0.1.2', 'mock>=2.0.0'],
File "/Users/username/.pyenv/versions/3.7.1/lib/python3.7/site-packages/setuptools/__init__.py", line 129, in setup
return distutils.core.setup(**attrs)
File "/Users/username/.pyenv/versions/3.7.1/lib/python3.7/distutils/core.py", line 148, in setup
dist.run_commands()
File "/Users/username/.pyenv/versions/3.7.1/lib/python3.7/distutils/dist.py", line 966, in run_commands
self.run_command(cmd)
File "/Users/username/.pyenv/versions/3.7.1/lib/python3.7/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/private/var/folders/pq/s_dm6c0d183642pp933rkcqm0000gn/T/pip-install-8w4_fiaf/pygraphviz/setup_commands.py", line 44, in modified_run
self.include_path, self.library_path = get_graphviz_dirs()
File "/private/var/folders/pq/s_dm6c0d183642pp933rkcqm0000gn/T/pip-install-8w4_fiaf/pygraphviz/setup_extra.py", line 162, in get_graphviz_dirs
include_dirs, library_dirs = _try_configure(include_dirs, library_dirs, _pkg_config)
File "/private/var/folders/pq/s_dm6c0d183642pp933rkcqm0000gn/T/pip-install-8w4_fiaf/pygraphviz/setup_extra.py", line 117, in _try_configure
i, l = try_function()
File "/private/var/folders/pq/s_dm6c0d183642pp933rkcqm0000gn/T/pip-install-8w4_fiaf/pygraphviz/setup_extra.py", line 72, in _pkg_config
output = S.check_output(['pkg-config', '--libs-only-L', 'libcgraph'])
File "/Users/username/.pyenv/versions/3.7.1/lib/python3.7/subprocess.py", line 389, in check_output
**kwargs).stdout
File "/Users/username/.pyenv/versions/3.7.1/lib/python3.7/subprocess.py", line 481, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['pkg-config', '--libs-only-L', 'libcgraph']' returned non-zero exit status 1.
----------------------------------------
Command "/Users/username/.pyenv/versions/3.7.1/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/pq/s_dm6c0d183642pp933rkcqm0000gn/T/pip-install-8w4_fiaf/pygraphviz/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/pq/s_dm6c0d183642pp933rkcqm0000gn/T/pip-record-fag39uff/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/pq/s_dm6c0d183642pp933rkcqm0000gn/T/pip-install-8w4_fiaf/pygraphviz/
実行してみたところ上記のようなエラーに遭遇しました。
どうやら、依存するライブラリが無いらしいのでbrew
でインストールします。
brew install graphviz
改めて実行。
pip install pygraphviz pydotplus
今度はきちんと入りました。
めでたしめでたし。
参考
http://hideharaaws.hatenablog.com/entry/2018/05/15/183533
https://qiita.com/ryoppippi/items/f484eb995ff1e913dd44