总之,使用brew install graphviz
,再执行pip install pygraphviz
也报错,错误内容如下:
Running setup.py install for pygraphviz ... error
ERROR: Command errored out with exit status 1:
command: /Users/user/opt/anaconda3/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/mz/qcpvt50n3pjb2vh7mfnckf900000gn/T/pip-install-gzipxcgs/pygraphviz_4fa1b9a5467b47568796340668d99220/setup.py'"'"'; __file__='"'"'/private/var/folders/mz/qcpvt50n3pjb2vh7mfnckf900000gn/T/pip-install-gzipxcgs/pygraphviz_4fa1b9a5467b47568796340668d99220/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' build_ext -I/usr/local/Cellar/graphviz/3.0.0/include -L/usr/local/Cellar/graphviz/3.0.0/lib install --record /private/var/folders/mz/qcpvt50n3pjb2vh7mfnckf900000gn/T/pip-record-yflo6qbu/install-record.txt --single-version-externally-managed --compile --install-headers /Users/user/opt/anaconda3/include/python3.9/pygraphviz
cwd: /private/var/folders/mz/qcpvt50n3pjb2vh7mfnckf900000gn/T/pip-install-gzipxcgs/pygraphviz_4fa1b9a5467b47568796340668d99220/
Complete output (11 lines):
running build_ext
building 'pygraphviz._graphviz' extension
creating build
creating build/temp.macosx-10.9-x86_64-3.9
creating build/temp.macosx-10.9-x86_64-3.9/pygraphviz
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /Users/user/opt/anaconda3/include -arch x86_64 -I/Users/user/opt/anaconda3/include -fPIC -O2 -isystem /Users/user/opt/anaconda3/include -arch x86_64 -DSWIG_PYTHON_STRICT_BYTE_CHAR -I/usr/local/Cellar/graphviz/3.0.0/include -I/Users/user/opt/anaconda3/include/python3.9 -c pygraphviz/graphviz_wrap.c -o build/temp.macosx-10.9-x86_64-3.9/pygraphviz/graphviz_wrap.o
pygraphviz/graphviz_wrap.c:2711:10: fatal error: 'graphviz/cgraph.h' file not found
#include "graphviz/cgraph.h"
^~~~~~~~~~~~~~~~~~~
1 error generated.
error: command '/usr/bin/clang' failed with exit code 1
----------------------------------------
ERROR: Command errored out with exit status 1: /Users/user/opt/anaconda3/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/mz/qcpvt50n3pjb2vh7mfnckf900000gn/T/pip-install-gzipxcgs/pygraphviz_4fa1b9a5467b47568796340668d99220/setup.py'"'"'; __file__='"'"'/private/var/folders/mz/qcpvt50n3pjb2vh7mfnckf900000gn/T/pip-install-gzipxcgs/pygraphviz_4fa1b9a5467b47568796340668d99220/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' build_ext -I/usr/local/Cellar/graphviz/3.0.0/include -L/usr/local/Cellar/graphviz/3.0.0/lib install --record /private/var/folders/mz/qcpvt50n3pjb2vh7mfnckf900000gn/T/pip-record-yflo6qbu/install-record.txt --single-version-externally-managed --compile --install-headers /Users/user/opt/anaconda3/include/python3.9/pygraphviz Check the logs for full command output.
解决方案:
conda install --channel conda-forge pygraphviz
搞定问题。