Reputation: 271
I'm having trouble installing pygraphviz and I'm using Anaconda on macOS Monterey.
I already had graphviz on Anaconda. I then did
brew install graphviz
and then
pip install pygraphviz
but I keep getting this error:
Collecting pygraphviz
Using cached pygraphviz-1.7.zip (118 kB)
Building wheels for collected packages: pygraphviz
Building wheel for pygraphviz (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /Users/susiekim4/opt/anaconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/j5/z34rlnbj2l94p1hh0x_hkkjw0000gn/T/pip-install-zr2twxnl/pygraphviz_e78bc2c823034812a5ffbd6ef61160d7/setup.py'"'"'; __file__='"'"'/private/var/folders/j5/z34rlnbj2l94p1hh0x_hkkjw0000gn/T/pip-install-zr2twxnl/pygraphviz_e78bc2c823034812a5ffbd6ef61160d7/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/j5/z34rlnbj2l94p1hh0x_hkkjw0000gn/T/pip-wheel-4fuwg_2b
cwd: /private/var/folders/j5/z34rlnbj2l94p1hh0x_hkkjw0000gn/T/pip-install-zr2twxnl/pygraphviz_e78bc2c823034812a5ffbd6ef61160d7/
Complete output (71 lines):
running bdist_wheel
running build
running build_py
creating build
creating build/lib.macosx-10.9-x86_64-3.8
creating build/lib.macosx-10.9-x86_64-3.8/pygraphviz
copying pygraphviz/scraper.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz
copying pygraphviz/graphviz.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz
copying pygraphviz/__init__.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz
copying pygraphviz/agraph.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz
copying pygraphviz/testing.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz
creating build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
copying pygraphviz/tests/test_unicode.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
copying pygraphviz/tests/test_scraper.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
copying pygraphviz/tests/test_readwrite.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
copying pygraphviz/tests/test_string.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
copying pygraphviz/tests/__init__.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
copying pygraphviz/tests/test_html.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
copying pygraphviz/tests/test_node_attributes.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
copying pygraphviz/tests/test_drawing.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
copying pygraphviz/tests/test_subgraph.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
copying pygraphviz/tests/test_close.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
copying pygraphviz/tests/test_edge_attributes.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
copying pygraphviz/tests/test_clear.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
copying pygraphviz/tests/test_layout.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
copying pygraphviz/tests/test_attribute_defaults.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
copying pygraphviz/tests/test_graph.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
running egg_info
writing pygraphviz.egg-info/PKG-INFO
writing dependency_links to pygraphviz.egg-info/dependency_links.txt
writing top-level names to pygraphviz.egg-info/top_level.txt
reading manifest file 'pygraphviz.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching '*.png' under directory 'doc'
warning: no files found matching '*.txt' under directory 'doc'
warning: no files found matching '*.css' under directory 'doc'
warning: no previously-included files matching '*~' found anywhere in distribution
warning: no previously-included files matching '*.pyc' found anywhere in distribution
warning: no previously-included files matching '.svn' found anywhere in distribution
no previously-included directories found matching 'doc/build'
writing manifest file 'pygraphviz.egg-info/SOURCES.txt'
copying pygraphviz/graphviz.i -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz
copying pygraphviz/graphviz_wrap.c -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz
running build_ext
building 'pygraphviz._graphviz' extension
creating build/temp.macosx-10.9-x86_64-3.8
creating build/temp.macosx-10.9-x86_64-3.8/pygraphviz
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/susiekim4/opt/anaconda3/include -arch x86_64 -I/Users/susiekim4/opt/anaconda3/include -arch x86_64 -I/Users/susiekim4/opt/anaconda3/include/python3.8 -c pygraphviz/graphviz_wrap.c -o build/temp.macosx-10.9-x86_64-3.8/pygraphviz/graphviz_wrap.o
pygraphviz/graphviz_wrap.c:1756:7: warning: 'tp_print' is deprecated [-Wdeprecated-declarations]
0, /* tp_print */
^
/Users/susiekim4/opt/anaconda3/include/python3.8/cpython/object.h:260:5: note: 'tp_print' has been explicitly marked deprecated here
Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
^
/Users/susiekim4/opt/anaconda3/include/python3.8/pyport.h:515:54: note: expanded from macro 'Py_DEPRECATED'
#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
^
pygraphviz/graphviz_wrap.c:1923:7: warning: 'tp_print' is deprecated [-Wdeprecated-declarations]
0, /* tp_print */
^
/Users/susiekim4/opt/anaconda3/include/python3.8/cpython/object.h:260:5: note: 'tp_print' has been explicitly marked deprecated here
Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
^
/Users/susiekim4/opt/anaconda3/include/python3.8/pyport.h:515:54: note: expanded from macro 'Py_DEPRECATED'
#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
^
pygraphviz/graphviz_wrap.c:2711:10: fatal error: 'graphviz/cgraph.h' file not found
#include "graphviz/cgraph.h"
^~~~~~~~~~~~~~~~~~~
2 warnings and 1 error generated.
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Failed building wheel for pygraphviz
Running setup.py clean for pygraphviz
Failed to build pygraphviz
Installing collected packages: pygraphviz
Running setup.py install for pygraphviz ... error
ERROR: Command errored out with exit status 1:
command: /Users/susiekim4/opt/anaconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/j5/z34rlnbj2l94p1hh0x_hkkjw0000gn/T/pip-install-zr2twxnl/pygraphviz_e78bc2c823034812a5ffbd6ef61160d7/setup.py'"'"'; __file__='"'"'/private/var/folders/j5/z34rlnbj2l94p1hh0x_hkkjw0000gn/T/pip-install-zr2twxnl/pygraphviz_e78bc2c823034812a5ffbd6ef61160d7/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/j5/z34rlnbj2l94p1hh0x_hkkjw0000gn/T/pip-record-pnja99aw/install-record.txt --single-version-externally-managed --compile --install-headers /Users/susiekim4/opt/anaconda3/include/python3.8/pygraphviz
cwd: /private/var/folders/j5/z34rlnbj2l94p1hh0x_hkkjw0000gn/T/pip-install-zr2twxnl/pygraphviz_e78bc2c823034812a5ffbd6ef61160d7/
Complete output (71 lines):
running install
running build
running build_py
creating build
creating build/lib.macosx-10.9-x86_64-3.8
creating build/lib.macosx-10.9-x86_64-3.8/pygraphviz
copying pygraphviz/scraper.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz
copying pygraphviz/graphviz.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz
copying pygraphviz/__init__.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz
copying pygraphviz/agraph.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz
copying pygraphviz/testing.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz
creating build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
copying pygraphviz/tests/test_unicode.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
copying pygraphviz/tests/test_scraper.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
copying pygraphviz/tests/test_readwrite.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
copying pygraphviz/tests/test_string.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
copying pygraphviz/tests/__init__.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
copying pygraphviz/tests/test_html.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
copying pygraphviz/tests/test_node_attributes.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
copying pygraphviz/tests/test_drawing.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
copying pygraphviz/tests/test_subgraph.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
copying pygraphviz/tests/test_close.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
copying pygraphviz/tests/test_edge_attributes.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
copying pygraphviz/tests/test_clear.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
copying pygraphviz/tests/test_layout.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
copying pygraphviz/tests/test_attribute_defaults.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
copying pygraphviz/tests/test_graph.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
running egg_info
writing pygraphviz.egg-info/PKG-INFO
writing dependency_links to pygraphviz.egg-info/dependency_links.txt
writing top-level names to pygraphviz.egg-info/top_level.txt
reading manifest file 'pygraphviz.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching '*.png' under directory 'doc'
warning: no files found matching '*.txt' under directory 'doc'
warning: no files found matching '*.css' under directory 'doc'
warning: no previously-included files matching '*~' found anywhere in distribution
warning: no previously-included files matching '*.pyc' found anywhere in distribution
warning: no previously-included files matching '.svn' found anywhere in distribution
no previously-included directories found matching 'doc/build'
writing manifest file 'pygraphviz.egg-info/SOURCES.txt'
copying pygraphviz/graphviz.i -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz
copying pygraphviz/graphviz_wrap.c -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz
running build_ext
building 'pygraphviz._graphviz' extension
creating build/temp.macosx-10.9-x86_64-3.8
creating build/temp.macosx-10.9-x86_64-3.8/pygraphviz
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/susiekim4/opt/anaconda3/include -arch x86_64 -I/Users/susiekim4/opt/anaconda3/include -arch x86_64 -I/Users/susiekim4/opt/anaconda3/include/python3.8 -c pygraphviz/graphviz_wrap.c -o build/temp.macosx-10.9-x86_64-3.8/pygraphviz/graphviz_wrap.o
pygraphviz/graphviz_wrap.c:1756:7: warning: 'tp_print' is deprecated [-Wdeprecated-declarations]
0, /* tp_print */
^
/Users/susiekim4/opt/anaconda3/include/python3.8/cpython/object.h:260:5: note: 'tp_print' has been explicitly marked deprecated here
Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
^
/Users/susiekim4/opt/anaconda3/include/python3.8/pyport.h:515:54: note: expanded from macro 'Py_DEPRECATED'
#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
^
pygraphviz/graphviz_wrap.c:1923:7: warning: 'tp_print' is deprecated [-Wdeprecated-declarations]
0, /* tp_print */
^
/Users/susiekim4/opt/anaconda3/include/python3.8/cpython/object.h:260:5: note: 'tp_print' has been explicitly marked deprecated here
Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
^
/Users/susiekim4/opt/anaconda3/include/python3.8/pyport.h:515:54: note: expanded from macro 'Py_DEPRECATED'
#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
^
pygraphviz/graphviz_wrap.c:2711:10: fatal error: 'graphviz/cgraph.h' file not found
#include "graphviz/cgraph.h"
^~~~~~~~~~~~~~~~~~~
2 warnings and 1 error generated.
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /Users/susiekim4/opt/anaconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/j5/z34rlnbj2l94p1hh0x_hkkjw0000gn/T/pip-install-zr2twxnl/pygraphviz_e78bc2c823034812a5ffbd6ef61160d7/setup.py'"'"'; __file__='"'"'/private/var/folders/j5/z34rlnbj2l94p1hh0x_hkkjw0000gn/T/pip-install-zr2twxnl/pygraphviz_e78bc2c823034812a5ffbd6ef61160d7/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/j5/z34rlnbj2l94p1hh0x_hkkjw0000gn/T/pip-record-pnja99aw/install-record.txt --single-version-externally-managed --compile --install-headers /Users/susiekim4/opt/anaconda3/include/python3.8/pygraphviz Check the logs for full command output.
I've tried pip3 install
, pip install cgraph
, and the other solutions.
What am I missing?
Upvotes: 26
Views: 13315
Reputation: 8536
I tried all the suggested answers without any luck, then found this to work:
brew install graphviz
export PATH=$(brew --prefix graphviz):$PATH
export CFLAGS="-I $(brew --prefix graphviz)/include"
export LDFLAGS="-L $(brew --prefix graphviz)/lib"
pip install pygraphviz
solution found here: https://github.com/iriusrisk/startleft/issues/329
Upvotes: 30
Reputation: 101
I have a pyenv running python 3.11.0, pip 24.0
When I try to $pip install pygraphviz
I get the same error:
pygraphviz/graphviz_wrap.c:3020:10: fatal error: 'graphviz/cgraph.h' file not found
However for me, I get
error: command '/usr/bin/clang' failed with exit code 1
instead of
error: command 'gcc' failed with exit status 1
(what you got). But I believe it can be resolved in the same manner. So what I did was
$pip install pygraphviz --verbose > error.log 2>&1
This is to get the error into the file so I can search through it (you can name 'error.log' however you like). Then I did view error.log
and searched for /clang
(in your case, you can do /gcc
). Then I found this:
clang -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -DSWIG_PYTHON_STRICT_BYTE_CHAR -I/Users/royyc/.pyenv/versions/3.11.0/include/python3.11 -c pygraphviz/graphviz_wrap.c -o build/temp.macosx-13.0-arm64-cpython-311/pygraphviz/graphviz_wrap.o
Made note of
-I/Applications/Xcode.app/Contents/Developer/Platforms/ MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
The -I
means include path while downloading pygraphviz. So it will look into this path to find the 'cgraph.h' file
The issue was that my cgraph.h file is located in these places (use $locate cgraph.h
):
/opt/homebrew/Cellar/gcc/13.2.0/lib/gcc/current/gcc/aarch64-apple-darwin23/13/plugin/include/cgraph.h /opt/homebrew/Cellar/graphviz/10.0.1/include/graphviz/cgraph.h
Since we got the fatal error that 'graphviz/cgraph.h' file not found, I did
sudo cp -R /opt/homebrew/Cellar/graphviz/10.0.1/include/graphviz /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
to copy all the files in
/opt/homebrew/Cellar/graphviz/10.0.1/include/graphviz
(that includes cgraph.h and other files) to
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
since this is (-I
) included in the path during build.
That resolved the issue for me:)
Upvotes: 0
Reputation: 335
I use python3.12 and this is what worked for me(thanks to @Olshansky)
after brew install graphviz
:
python3.12 -m pip install \
--config-setting="--global-option=build_ext" \
--config-setting="--global-option=-I$(brew --prefix graphviz)/include/" \
--config-setting="--global-option=-L$(brew --prefix graphviz)/lib/" \
pygraphviz
Upvotes: 9
Reputation: 4033
On Mac, you must pass the path of the install directory so the wheel compiler can find the graphviz header and library files. Here's how:
Use Homebrew to install graphviz:
brew install graphviz
Get the install directory:
brew --prefix graphviz
Set GRAPHVIZ_DIR
to where it was installed:
export GRAPHVIZ_DIR="[INSTALL PATH HERE]"
Install graphviz specifying the path:
If using pip
23.2 or later:
export GRAPHVIZ_DIR="$(brew --prefix graphviz)"
pip install pygraphviz \
--global-option=build_ext \
--global-option="-I$GRAPHVIZ_DIR/include" \
--global-option="-L$GRAPHVIZ_DIR/lib"
If using an earlier version of pip
:
export GRAPHVIZ_DIR="$(brew --prefix graphviz)"
pip install pygraphviz \
--config-settings=--global-option=build_ext \
--config-settings=--global-option="-I$GRAPHVIZ_DIR/include" \
--config-settings=--global-option="-L$GRAPHVIZ_DIR/lib"
With these additions, the package should be compiled and installed successfully:
Collecting pygraphviz
Using cached pygraphviz-1.11.zip (120 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: pygraphviz
Building wheel for pygraphviz (pyproject.toml) ... done
Created wheel for pygraphviz: filename=pygraphviz-1.11-cp311-cp311-macosx_13_0_arm64.whl size=100586 sha256=0d6e56168321d335706a6c6789a006b8d2831bbd32b1cd28bd8fb2238122f73b
Stored in directory: .../pip/wheels/c8/03/73/b754941d55845a8b326f6de528bc70e65774838c76effa6d51
Successfully built pygraphviz
Installing collected packages: pygraphviz
Successfully installed pygraphviz-1.11
Upvotes: 47
Reputation: 6404
Highly recommend the only solution that worked for me from azabraoo:
pip install --global-option=build_ext --global-option="-I$(brew --prefix graphviz)/include/" --global-option="-L$(brew --prefix graphviz)/lib/" pygraphviz
Upvotes: 1
Reputation: 31339
For me it worked using this:
python -m pip install \
--global-option=build_ext \
--global-option="-I$(brew --prefix graphviz)/include/" \
--global-option="-L$(brew --prefix graphviz)/lib/" \
pygraphviz
Upvotes: 16
Reputation: 513
I copy /opt/homebrew/bin/dot to /usr/local/bin/dot, restart the visual studio code and done!
Command:
sudo cp /opt/homebrew/bin/dot /usr/local/bin/dot
Upvotes: -1