Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation:fatal error: 'graphviz/cgraph.h' file not found #11

Closed
hebijiandai opened this issue Mar 7, 2014 · 70 comments
Closed

Installation:fatal error: 'graphviz/cgraph.h' file not found #11

hebijiandai opened this issue Mar 7, 2014 · 70 comments

Comments

@hebijiandai
Copy link

I use mac os
I run the code:

python setup.py install 

But it didn't success
So I write the dirs:

include_dirs = "/Users/allenlee/Downloads/pygraphviz-master/pygraphviz"
library_dirs = "/Users/allenlee/Downloads/pygraphviz-master/pygraphviz"

But it cause the error

AllendeMacBook-Pro:pygraphviz-master allenlee$ python setup.py install
library_dirs=/Users/allenlee/Downloads/pygraphviz-master/pygraphviz
include_dirs=/Users/allenlee/Downloads/pygraphviz-master/pygraphviz
running install
running build
running build_py
running build_ext
building 'pygraphviz._graphviz' extension
/usr/bin/clang -fno-strict-aliasing -fno-common -dynamic -arch i386 -arch x86_64 -g -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/allenlee/Downloads/pygraphviz-master/pygraphviz -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c pygraphviz/graphviz_wrap.c -o build/temp.macosx-10.6-intel-2.7/pygraphviz/graphviz_wrap.o
pygraphviz/graphviz_wrap.c:2969:10: fatal error: 'graphviz/cgraph.h' file not found
#include "graphviz/cgraph.h"
         ^

Could you help to solve it?Thanks a lot

@bugamn
Copy link

bugamn commented Mar 7, 2014

Do you have the graphviz development files installed? On Ubuntu, for example, they are in a package called libgraphviz-dev. I don't know how one would install them on a Mac.

@hebijiandai
Copy link
Author

I use pip install graphviz to install it ,maybe graphviz is the key point of this error

@bugamn
Copy link

bugamn commented Mar 7, 2014

Can you remove the dirs you wrote and post the error message?

EDIT: the dirs that you added should have the graphviz files (not pygraphviz). It seems that the problem is that you need to install graphviz, which isn't a python package, so I don't see how you would install it with pip.

Download link for MacOS graphviz: http://www.graphviz.org/Download_macos.php

@hebijiandai
Copy link
Author

OK ,I finish the job,thanks a lot!

@hagberg hagberg closed this as completed Sep 21, 2014
@whu-zhigao
Copy link

How did you solve this problem? I have the same situation with you but I use windows 7

@whu-zhigao
Copy link

I use Windoews 7 OS
It cause the error:
D:\mingw-get\bin\gcc.exe -mdll -O -Wall -DGVDLL -ID:\Python34\include -ID:\Pytho
n34\include -c pygraphviz/graphviz_wrap.c -o build\temp.win32-3.4\Release\pygrap
hviz\graphviz_wrap.o
pygraphviz/graphviz_wrap.c:2954:29: fatal error: graphviz/cgraph.h: No such file
or directory
#include "graphviz/cgraph.h"
^
compilation terminated.
error: command 'D:\mingw-get\bin\gcc.exe' failed with exit status 1

@hagberg hagberg modified the milestone: pygraphivz-1.3 Sep 5, 2015
@AgalyaLoganathan
Copy link

Hi,
I'm using yosemite and I have installed grapghviz using Homebrew. But when I try to run 'pip install pygraphviz', I still encounter the same issue. (i.e)

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

----------------------------------------

Command "/usr/bin/python -c "import setuptools, tokenize;file='/private/var/folders/sj/yk1843h92lsgdxvzbvjxhk_80000gn/T/pip-build-KIO55c/pygraphviz/setup.py';exec(compile(getattr(tokenize, 'open', open)(file).read().replace('\r\n', '\n'), file, 'exec'))" install --record /var/folders/sj/yk1843h92lsgdxvzbvjxhk_80000gn/T/pip-SwBY6j-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/sj/yk1843h92lsgdxvzbvjxhk_80000gn/T/pip-build-KIO55c/pygraphviz

Can you please elaborate on how to resolve the issue?

@saltthehash
Copy link

Having the same problem as @AgalyaLoganathan on OS X 10.11 El Capitan

EDIT: I managed to fix it by doing two things:

  1. Install pygraphviz from setup.py like so:
    python setup.py install --include-path=/usr/local/Cellar/graphviz/2.38.0/include --library-path=/usr/local/Cellar/graphviz/2.38.0/lib
    I saw a note about issues detecting the path and the example given on the website I was looking at still didn't work because it had the include directory to "include" /graphviz, which is why it could not detect "graphviz/graphviz/cgraph.h". Just double check that this is the same version of graphviz (obviously this particular path is specific to OS X users using homebrew, but making sure that the correct path for lib and include is probably useful)
  2. Make sure pydot2 is installed, and NOT pydot. After uninstalling pydot and installing pydot2, everything started working fine.

@a-ruzin
Copy link

a-ruzin commented Dec 11, 2015

My problem was:

pip install pygraphviz
....
#include "graphviz/cgraph.h"
^
1 error generated.
error: command 'cc' failed with exit status 1
....

Fixed with:

/usr/local/Cellar/graphviz/2.38.0/include/graphviz> ln -s . graphviz

pip install pygraphviz
...
Successfully installed pygraphviz-1.3.1

@thedimlebowski
Copy link

Can be solved with

pip install --global-option=build_ext --global-option="-I/usr/local/Cellar/graphviz/2.38.0/include/"  --global-option="-L/usr/local/Cellar/graphviz/2.38.0/lib/" pygraphviz

Or with: (credits to http://www.alexandrejoseph.com/blog/2016-02-10-install-pygraphviz-mac-osx.html)

pip install --install-option="--include-path=/usr/local/Cellar/graphviz/2.38.0/include/graphviz"  --install-option="--library-path=/usr/local/Cellar/graphviz/2.38.0/lib/graphviz" pygraphviz

@drandreaskrueger
Copy link

pip install pygraphviz

Windows 7

----------------------------------------
Failed building wheel for pygraphviz

Running setup.py install for pygraphviz
Complete output from command c:\anaconda\python.exe -c "import setuptools, tokenize;__file__='c:\\users\\andreas\\appdata\\local\\temp\\pip-build-gjzf2d\\pygraphviz\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\andreas\appdata\local\temp\pip-nqpkoi-record\install-record.txt --single-version-externally-managed --compile:

...

building 'pygraphviz._graphviz' extension
C:\Users\Andreas\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -INone -Ic:\anaconda\include -Ic:\anaconda\PC /Tcpygraphviz/graphviz_wrap.c /Fobuild\temp.win-amd64-2.7\Release\pygraphviz/graphviz_wrap.obj 
graphviz_wrap.c
pygraphviz/graphviz_wrap.c(2954) : fatal error C1083: Cannot open include file: 'graphviz/cgraph.h': No such file or directory
error: command 'C:\\Users\\Andreas\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\amd64\\cl.exe' failed with exit status 2

@hagberg
Copy link
Contributor

hagberg commented Jan 17, 2016

The original post was about mac os.

But with your windows install attempt either you are missing the graphviz package (or parts of it) or else the pygraphviz setup code is not finding your graphviz installation and you may need to explicitly set that.

@drandreaskrueger
Copy link

Thanks a lot. Yes:

http://graphviz.org/Download_windows.php

Then I could solve riddles, one after the other ...
Using your command as inspiration, transposed to windows:

pip install --global-option=build_ext --global-option="-IC:\PROGRA~2\Graphviz2.38\include"  --global-option="-LC:\PROGRA~2\Graphviz2.38\lib\release\lib" pygraphviz

but now I get "49 unresolved externals"

    C:\Users\Andreas\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\PROGRA~2\Graphviz2.38\lib\release\lib /LIBPATH:c:\anaconda\libs /LIBPATH:c:\anaconda\PCbuild\amd64 /LIBPATH:c:\anaconda\PC\VS9.0\amd64 cgraph.lib cdt.lib /EXPORT:init_graphviz build\temp.win-amd64-2.7\Release\pygraphviz/graphviz_wrap.obj /OUT:build\lib.win-amd64-2.7\pygraphviz\_graphviz.pyd /IMPLIB:build\temp.win-amd64-2.7\Release\pygraphviz\_graphviz.lib /MANIFESTFILE:build\temp.win-amd64-2.7\Release\pygraphviz\_graphviz.pyd.manifest
graphviz_wrap.obj : warning LNK4197: export 'init_graphviz' specified multiple times; using first specification
   Creating library build\temp.win-amd64-2.7\Release\pygraphviz\_graphviz.lib and object build\temp.win-amd64-2.7\Release\pygraphviz\_graphviz.exp
graphviz_wrap.obj : error LNK2019: unresolved external symbol agsafeset referenced in function agsafeset_label
graphviz_wrap.obj : error LNK2019: unresolved external symbol agstrdup_html referenced in function agsafeset_label
...
graphviz_wrap.obj : error LNK2019: unresolved external symbol Agundirected referenced in function Swig_var_Agundirected_get
graphviz_wrap.obj : error LNK2019: unresolved external symbol Agstrictundirected referenced in function Swig_var_Agstrictundirected_get
build\lib.win-amd64-2.7\pygraphviz\_graphviz.pyd : fatal error LNK1120: 49 unresolved externals
error: command 'C:\\Users\\Andreas\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\amd64\\link.exe' failed with exit status 1120

@steven7777
Copy link

On Mac OS 10.11.3, using macport, solved this issue with :

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

@jiangpengnju
Copy link

@steven7777
The "include-path" and "install-option" depend on how you installed the graphviz.
I uses brew to install graphviz and the paths are: "/usr/local/include", "/usr/local/lib"

@manthis
Copy link

manthis commented Aug 3, 2016

@steven7777 @jiangpengnju

I'm on Mac OS 10.11.6. When I try setting up pygraphviz through pip it tells me it can't find graphviz. When I specify the library and include path it doesn't recognize the options. I have opened an issue here: #100.

How did you solve this problem?

@jiangpengnju
Copy link

@manthis Already answer you in you issue #100

@Puertarra
Copy link

Tks @Steven777
It works on 10.12.1 as well

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

@jason-s
Copy link

jason-s commented Jan 14, 2017

this worked for me: I have Mac OS X 10.6 (Snow Leopard) and the problem was that the default include path was set to /opt/local/include/graphviz and caused this error during compilation:

pygraphviz/graphviz_wrap.c:2954:29: error: graphviz/cgraph.h: No such file or directory

which is stupid because the default include path is not consistent, it needed to remove the last graphviz part of the path since the #include "graphviz/cgraph.h" is relative to the include path.

Fixed via

sudo pip install pygraphviz --global-option=build_ext --global-option="-I/opt/local/include"

@vikmary
Copy link

vikmary commented Feb 9, 2017

brew install graphviz
python setup.py install
fixed the issue for me (Mac).

@manum
Copy link

manum commented Oct 5, 2017

I had a problem due to El Capitan https://arstechnica.com/gadgets/2015/09/os-x-10-11-el-capitan-the-ars-technica-review/8/#h1

solved it by adding --user to pip

pip install --user --install-option="--include-path=/opt/local/include" --install-option="--library-path=/opt/local/lib" pygraphviz

@litchfield
Copy link

This worked for me on Mojave.

Step 1.
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/Cellar/graphviz/2.40.1/include/graphviz/

Step 2.
pip install pygraphviz

@ikarthikng
Copy link

I followed below steps

apt-get update
apt-get install libgraphviz-dev
pip install pygraphviz

It worked for me

@drozdowsky
Copy link

Catalina (10.15.2)

brew install graphviz
pip install --install-option="--include-path=/usr/local/Cellar/graphviz/2.42.2/include/"  --install-option="--library-path=/usr/local/Cellar/graphviz/2.42.2/lib/" pygraphviz

@felipebsouza
Copy link

Catalina (10.15.2)

brew install graphviz
pip install --install-option="--include-path=/usr/local/Cellar/graphviz/2.42.2/include/"  --install-option="--library-path=/usr/local/Cellar/graphviz/2.42.2/lib/" pygraphviz

worked for me too! thanks

@KelSolaar
Copy link

Having issue the dreaded issue with macOs Sonoma, Python 3.12 and Homebrew. I cannot fix it so far:

$ CFLAGS=-I$(brew --prefix graphviz)/include LDFLAGS=$(brew --prefix graphviz)/lib pip install pygraphviz
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) ... error
  error: subprocess-exited-with-error

  × Building wheel for pygraphviz (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [54 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.macosx-13-arm64-cpython-312
      creating build/lib.macosx-13-arm64-cpython-312/pygraphviz
      copying pygraphviz/scraper.py -> build/lib.macosx-13-arm64-cpython-312/pygraphviz
      copying pygraphviz/graphviz.py -> build/lib.macosx-13-arm64-cpython-312/pygraphviz
      copying pygraphviz/__init__.py -> build/lib.macosx-13-arm64-cpython-312/pygraphviz
      copying pygraphviz/agraph.py -> build/lib.macosx-13-arm64-cpython-312/pygraphviz
      copying pygraphviz/testing.py -> build/lib.macosx-13-arm64-cpython-312/pygraphviz
      creating build/lib.macosx-13-arm64-cpython-312/pygraphviz/tests
      copying pygraphviz/tests/test_unicode.py -> build/lib.macosx-13-arm64-cpython-312/pygraphviz/tests
      copying pygraphviz/tests/test_scraper.py -> build/lib.macosx-13-arm64-cpython-312/pygraphviz/tests
      copying pygraphviz/tests/test_readwrite.py -> build/lib.macosx-13-arm64-cpython-312/pygraphviz/tests
      copying pygraphviz/tests/test_string.py -> build/lib.macosx-13-arm64-cpython-312/pygraphviz/tests
      copying pygraphviz/tests/__init__.py -> build/lib.macosx-13-arm64-cpython-312/pygraphviz/tests
      copying pygraphviz/tests/test_html.py -> build/lib.macosx-13-arm64-cpython-312/pygraphviz/tests
      copying pygraphviz/tests/test_node_attributes.py -> build/lib.macosx-13-arm64-cpython-312/pygraphviz/tests
      copying pygraphviz/tests/test_drawing.py -> build/lib.macosx-13-arm64-cpython-312/pygraphviz/tests
      copying pygraphviz/tests/test_repr_mimebundle.py -> build/lib.macosx-13-arm64-cpython-312/pygraphviz/tests
      copying pygraphviz/tests/test_subgraph.py -> build/lib.macosx-13-arm64-cpython-312/pygraphviz/tests
      copying pygraphviz/tests/test_close.py -> build/lib.macosx-13-arm64-cpython-312/pygraphviz/tests
      copying pygraphviz/tests/test_edge_attributes.py -> build/lib.macosx-13-arm64-cpython-312/pygraphviz/tests
      copying pygraphviz/tests/test_clear.py -> build/lib.macosx-13-arm64-cpython-312/pygraphviz/tests
      copying pygraphviz/tests/test_layout.py -> build/lib.macosx-13-arm64-cpython-312/pygraphviz/tests
      copying pygraphviz/tests/test_attribute_defaults.py -> build/lib.macosx-13-arm64-cpython-312/pygraphviz/tests
      copying pygraphviz/tests/test_graph.py -> build/lib.macosx-13-arm64-cpython-312/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'
      adding license file 'LICENSE'
      writing manifest file 'pygraphviz.egg-info/SOURCES.txt'
      copying pygraphviz/graphviz.i -> build/lib.macosx-13-arm64-cpython-312/pygraphviz
      copying pygraphviz/graphviz_wrap.c -> build/lib.macosx-13-arm64-cpython-312/pygraphviz
      running build_ext
      building 'pygraphviz._graphviz' extension
      creating build/temp.macosx-13-arm64-cpython-312
      creating build/temp.macosx-13-arm64-cpython-312/pygraphviz
      clang -fno-strict-overflow -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk -I/opt/homebrew/opt/graphviz/include -DSWIG_PYTHON_STRICT_BYTE_CHAR -I/Users/kelsolaar/Library/Caches/pypoetry/virtualenvs/colour-science-49B8_mty-py3.12/include -I/opt/homebrew/opt/[email protected]/Frameworks/Python.framework/Versions/3.12/include/python3.12 -c pygraphviz/graphviz_wrap.c -o build/temp.macosx-13-arm64-cpython-312/pygraphviz/graphviz_wrap.o
      clang -bundle -undefined dynamic_lookup -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk /opt/homebrew/opt/graphviz/lib -I/opt/homebrew/opt/graphviz/include build/temp.macosx-13-arm64-cpython-312/pygraphviz/graphviz_wrap.o -lcdt -lcgraph -lgvc -o build/lib.macosx-13-arm64-cpython-312/pygraphviz/_graphviz.cpython-312-darwin.so
      ld: library 'cdt' not found
      clang: error: linker command failed with exit code 1 (use -v to see invocation)
      error: command '/usr/bin/clang' failed with exit code 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pygraphviz
Failed to build pygraphviz

@yakhoruzhenko
Copy link

For the new graphviz versions, on macOS the command would be:

export CFLAGS="-I/usr/local/Cellar/graphviz/9.0.0/include/" LDFLAGS="-L/usr/local/Cellar/graphviz/9.0.0/lib/"
pip install pygraphviz

I recommend using one-liner:

CFLAGS=-I$(brew --prefix graphviz)/include LDFLAGS=$(brew --prefix graphviz)/lib pip install pygraphviz

Advantages:

  • Free of reference to specific graphviz version
  • no global CFLAGS, LDFLAGS variables in your environment.

Thank you. This is the only one from the recent replies that helped me 🙇

@nicolasbalbontin
Copy link

Su ayuda porfavor:
CFLAGS=-I$(brew --prefix graphviz)/include LDFLAGS=$(brew --prefix graphviz)/lib pip install pygraphviz
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) ... error
error: subprocess-exited-with-error

× Building wheel for pygraphviz (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [54 lines of output]
running bdist_wheel
running build
running build_py
creating build
creating build/lib.macosx-10.9-universal2-cpython-311
creating build/lib.macosx-10.9-universal2-cpython-311/pygraphviz
copying pygraphviz/scraper.py -> build/lib.macosx-10.9-universal2-cpython-311/pygraphviz
copying pygraphviz/graphviz.py -> build/lib.macosx-10.9-universal2-cpython-311/pygraphviz
copying pygraphviz/init.py -> build/lib.macosx-10.9-universal2-cpython-311/pygraphviz
copying pygraphviz/agraph.py -> build/lib.macosx-10.9-universal2-cpython-311/pygraphviz
copying pygraphviz/testing.py -> build/lib.macosx-10.9-universal2-cpython-311/pygraphviz
creating build/lib.macosx-10.9-universal2-cpython-311/pygraphviz/tests
copying pygraphviz/tests/test_unicode.py -> build/lib.macosx-10.9-universal2-cpython-311/pygraphviz/tests
copying pygraphviz/tests/test_scraper.py -> build/lib.macosx-10.9-universal2-cpython-311/pygraphviz/tests
copying pygraphviz/tests/test_readwrite.py -> build/lib.macosx-10.9-universal2-cpython-311/pygraphviz/tests
copying pygraphviz/tests/test_string.py -> build/lib.macosx-10.9-universal2-cpython-311/pygraphviz/tests
copying pygraphviz/tests/init.py -> build/lib.macosx-10.9-universal2-cpython-311/pygraphviz/tests
copying pygraphviz/tests/test_html.py -> build/lib.macosx-10.9-universal2-cpython-311/pygraphviz/tests
copying pygraphviz/tests/test_node_attributes.py -> build/lib.macosx-10.9-universal2-cpython-311/pygraphviz/tests
copying pygraphviz/tests/test_drawing.py -> build/lib.macosx-10.9-universal2-cpython-311/pygraphviz/tests
copying pygraphviz/tests/test_repr_mimebundle.py -> build/lib.macosx-10.9-universal2-cpython-311/pygraphviz/tests
copying pygraphviz/tests/test_subgraph.py -> build/lib.macosx-10.9-universal2-cpython-311/pygraphviz/tests
copying pygraphviz/tests/test_close.py -> build/lib.macosx-10.9-universal2-cpython-311/pygraphviz/tests
copying pygraphviz/tests/test_edge_attributes.py -> build/lib.macosx-10.9-universal2-cpython-311/pygraphviz/tests
copying pygraphviz/tests/test_clear.py -> build/lib.macosx-10.9-universal2-cpython-311/pygraphviz/tests
copying pygraphviz/tests/test_layout.py -> build/lib.macosx-10.9-universal2-cpython-311/pygraphviz/tests
copying pygraphviz/tests/test_attribute_defaults.py -> build/lib.macosx-10.9-universal2-cpython-311/pygraphviz/tests
copying pygraphviz/tests/test_graph.py -> build/lib.macosx-10.9-universal2-cpython-311/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'
adding license file 'LICENSE'
writing manifest file 'pygraphviz.egg-info/SOURCES.txt'
copying pygraphviz/graphviz.i -> build/lib.macosx-10.9-universal2-cpython-311/pygraphviz
copying pygraphviz/graphviz_wrap.c -> build/lib.macosx-10.9-universal2-cpython-311/pygraphviz
running build_ext
building 'pygraphviz._graphviz' extension
creating build/temp.macosx-10.9-universal2-cpython-311
creating build/temp.macosx-10.9-universal2-cpython-311/pygraphviz
clang -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -arch x86_64 -g -I/opt/homebrew/opt/graphviz/include -DSWIG_PYTHON_STRICT_BYTE_CHAR -I/Library/Frameworks/Python.framework/Versions/3.11/include/python3.11 -c pygraphviz/graphviz_wrap.c -o build/temp.macosx-10.9-universal2-cpython-311/pygraphviz/graphviz_wrap.o
clang -bundle -undefined dynamic_lookup -arch arm64 -arch x86_64 -g /opt/homebrew/opt/graphviz/lib -I/opt/homebrew/opt/graphviz/include build/temp.macosx-10.9-universal2-cpython-311/pygraphviz/graphviz_wrap.o -lcdt -lcgraph -lgvc -o build/lib.macosx-10.9-universal2-cpython-311/pygraphviz/_graphviz.cpython-311-darwin.so
ld: library 'cdt' not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command '/usr/bin/clang' failed with exit code 1
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for pygraphviz
Failed to build pygraphviz
ERROR: Could not build wheels for pygraphviz, which is required to install pyproject.toml-based projects

@chadbrewbaker
Copy link

Still broken on MacOS M1. yakhoruzhenko was close.
This works:

 python3 -m pip install  --use-pep517 \
                    --config-settings="--global-option=build_ext" \
                    --config-settings="--build-option=-I$(brew --prefix graphviz)/include/" \
                    --config-settings="--build-option=-L$(brew --prefix graphviz)/lib/" \
                    pygraphviz

@bwagner
Copy link

bwagner commented Nov 30, 2023

EDIT: thanks to atul016 for pointing out the omissions of /include and /lib in my solution.

Note: I'm using pip install-option --no-cache-dir to reproduce the uninstalled situation.

I assume you did: brew install graphviz.

python -Vis Python 3.12.0

macOS: 14.1.1 (Sonoma) on a MacBook Pro with Apple M1 Max

Before the experiments, create a virtual env and activate it, to create reproducible situation:

python -m venv ~/venv/pgv
source ~/venv/pgv/bin/activate
pip install --upgrade pip
  1. pip install --no-cache-dir pygraphviz

fails with:

      pygraphviz/graphviz_wrap.c:3020:10: fatal error: 'graphviz/cgraph.h' file not found
       3020 | #include "graphviz/cgraph.h"
            |          ^~~~~~~~~~~~~~~~~~~
      1 error generated.
      error: command '/opt/homebrew/opt/llvm/bin/clang' failed with exit code 1
  1. @chadbrewbaker ( == official instructions)
python3 -m pip install  --no-cache-dir --use-pep517 \
                    --config-settings="--global-option=build_ext" \
                    --config-settings="--build-option=-I$(brew --prefix graphviz)/include/" \
                    --config-settings="--build-option=-L$(brew --prefix graphviz)/lib/" \
                    pygraphviz

fails with the same error:

      pygraphviz/graphviz_wrap.c:3020:10: fatal error: 'graphviz/cgraph.h' file not found
       3020 | #include "graphviz/cgraph.h"
            |          ^~~~~~~~~~~~~~~~~~~
      1 error generated.
      error: command '/opt/homebrew/opt/llvm/bin/clang' failed with exit code 1
  1. CFLAGS=-I$(brew --prefix graphviz) LDFLAGS=-L$(brew --prefix graphviz) pip --no-cache-dir install pygraphviz

fails with the same error:

      pygraphviz/graphviz_wrap.c:3020:10: fatal error: 'graphviz/cgraph.h' file not found
       3020 | #include "graphviz/cgraph.h"
            |          ^~~~~~~~~~~~~~~~~~~
      1 error generated.
      error: command '/opt/homebrew/opt/llvm/bin/clang' failed with exit code 1
  1. install from local clone of pygraphviz succeeds
git clone https://github.com/pygraphviz/pygraphviz
cd pygraphviz

CFLAGS=-I$(brew --prefix graphviz)/include LDFLAGS=-L$(brew --prefix graphviz)/lib pip --no-cache-dir install .

Processing /.../pygraphviz
  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.12rc0.dev0-cp312-cp312-macosx_13_0_arm64.whl size=101213 sha256=382a0bd25f706c3c102586d9299d371965d4891609a92beacf9a098814745bce
  Stored in directory: /private/var/folders/zv/czfq38716j5417j45s_n94sc0000gr/T/pip-ephem-wheel-cache-e2tqh68a/wheels/f3/6a/9b/90428baf90719073e8a9dee6858613fb16110ed695d25bb83c
Successfully built pygraphviz
Installing collected packages: pygraphviz
Successfully installed pygraphviz-1.12rc0.dev0

@atul016
Copy link

atul016 commented Dec 7, 2023

Note: I'm using pip install-option --no-cache-dir to reproduce the uninstalled situation.

I assume you did: brew install graphviz.

python -Vis Python 3.12.0

macOS: 14.1.1 (Sonoma) on a MacBook Pro with Apple M1 Max

Before the experiments, create a virtual env and activate it, to create reproducible situation:

python -m venv ~/venv/pgv
source ~/venv/pgv/bin/activate
pip install --upgrade pip
  1. pip install --no-cache-dir pygraphviz

fails with:

      pygraphviz/graphviz_wrap.c:3020:10: fatal error: 'graphviz/cgraph.h' file not found
       3020 | #include "graphviz/cgraph.h"
            |          ^~~~~~~~~~~~~~~~~~~
      1 error generated.
      error: command '/opt/homebrew/opt/llvm/bin/clang' failed with exit code 1
  1. @chadbrewbaker ( == official instructions)
python3 -m pip install  --no-cache-dir --use-pep517 \
                    --config-settings="--global-option=build_ext" \
                    --config-settings="--build-option=-I$(brew --prefix graphviz)/include/" \
                    --config-settings="--build-option=-L$(brew --prefix graphviz)/lib/" \
                    pygraphviz

fails with the same error:

      pygraphviz/graphviz_wrap.c:3020:10: fatal error: 'graphviz/cgraph.h' file not found
       3020 | #include "graphviz/cgraph.h"
            |          ^~~~~~~~~~~~~~~~~~~
      1 error generated.
      error: command '/opt/homebrew/opt/llvm/bin/clang' failed with exit code 1
  1. CFLAGS=-I$(brew --prefix graphviz) LDFLAGS=-L$(brew --prefix graphviz) pip --no-cache-dir install pygraphviz

fails with the same error:

      pygraphviz/graphviz_wrap.c:3020:10: fatal error: 'graphviz/cgraph.h' file not found
       3020 | #include "graphviz/cgraph.h"
            |          ^~~~~~~~~~~~~~~~~~~
      1 error generated.
      error: command '/opt/homebrew/opt/llvm/bin/clang' failed with exit code 1
  1. install from local clone of pygraphviz succeeds
git clone https://github.com/pygraphviz/pygraphviz
cd pygraphviz

CFLAGS=-I$(brew --prefix graphviz) LDFLAGS=-L$(brew --prefix graphviz) pip --no-cache-dir install .

Processing /.../pygraphviz
  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.12rc0.dev0-cp312-cp312-macosx_13_0_arm64.whl size=101213 sha256=382a0bd25f706c3c102586d9299d371965d4891609a92beacf9a098814745bce
  Stored in directory: /private/var/folders/zv/czfq38716j5417j45s_n94sc0000gr/T/pip-ephem-wheel-cache-e2tqh68a/wheels/f3/6a/9b/90428baf90719073e8a9dee6858613fb16110ed695d25bb83c
Successfully built pygraphviz
Installing collected packages: pygraphviz
Successfully installed pygraphviz-1.12rc0.dev0

install from local clone of pygraphviz worked for me too with a small correction in install command

CFLAGS=-I$(brew --prefix graphviz)/include/ LDFLAGS=-L$(brew --prefix graphviz)/lib/ pip --no-cache-dir install .

@iskander-saitbatalov
Copy link

Greetings to all sufferers. I came here to help you. I don't know why I did this, but I compiled this library, although I don't even write in Python.

Configruation:
OS: iOS, Python: 3.12, pip 23.3.2:

Commands:

brew install graphviz
export GRAPHVIZ_LIB_DIR="$(brew --prefix graphviz)"
python3 -m pip install --use-pep517                                                                     \
                                    --config-settings="--global-option=build_ext"                       \
                                    --config-settings="--global-option=-I$GRAPHVIZ_LIB_DIR/include/"    \
                                    --config-settings="--global-option=-L$GRAPHVIZ_LIB_DIR/lib/"        \
                                   pygraphviz

@bwagner
Copy link

bwagner commented Jan 3, 2024

Confirming @iskander-saitbatalov's findings, that it is no longer necessary to clone the repo to install pygraphviz.

Note: I'm using pip install-option --no-cache-dir to reproduce the uninstalled situation.

I assume you did: brew install graphviz.

python -Vis Python 3.12.1
pip -Vis pip 23.3.2

macOS: 14.2.1 (Sonoma) on a MacBook Pro with Apple M1 Max

Before the experiments, create a virtual env and activate it, to create reproducible situation:

python -m venv ~/venv/pgv
source ~/venv/pgv/bin/activate
pip install --upgrade pip

Then install pygraphviz (NOTE: not using --use-pep517):

pip install --no-cache-dir \
  --config-settings="--global-option=build_ext" \
  --config-settings="--global-option=-I$(brew --prefix graphviz)/include/" \
  --config-settings="--global-option=-L$(brew --prefix graphviz)/lib/" \
  pygraphviz

Test it with (this should print pygraphviz's version number, e.g. 1.13):

python -c "import pygraphviz;print(pygraphviz.__version__)"

Once it succeeds, deactivate the virtual environment, delete it, and install pygraphviz in whatever environment you desire:

deactivate
rm -r ~/venv/pgv
pip install \
  --config-settings="--global-option=build_ext" \
  --config-settings="--global-option=-I$(brew --prefix graphviz)/include/" \
  --config-settings="--global-option=-L$(brew --prefix graphviz)/lib/" \
  pygraphviz

@tgrushka
Copy link

Only thing that worked for me is @bwagner 's final comment after trying dozens of different options. Please add to the install docs for macOS Sonoma.

pip install --no-cache-dir \
  --config-settings="--global-option=build_ext" \
  --config-settings="--global-option=-I$(brew --prefix graphviz)/include/" \
  --config-settings="--global-option=-L$(brew --prefix graphviz)/lib/" \
  pygraphviz

@rossbar
Copy link
Contributor

rossbar commented Jan 11, 2024

Note that this is what is currently recommended in the installation guide - if there are any additional tweaks required please raise an issue about it!

@jmkacz
Copy link

jmkacz commented Feb 18, 2024

Following the installation guide fails for me. I posted an issue on pypa/pip before finding this issue: pypa/pip#12531

@roskakori
Copy link

I did this to make it work:

  1. Add these lines to my ~/.zprofile (resp. ~/.profile if you are still using bash).
    # Required to build pygraphviz
    export CFLAGS="-I$(brew --prefix graphviz)/include/"                                                   
    export LDFLAGS="-L$(brew --prefix graphviz)/lib/"
  2. Open a new terminal (so new envvars are set).
  3. Retry to build/install pygraphviz.

This worked for me.

@bwagner
Copy link

bwagner commented Feb 22, 2024

Adding these environment variables globally and permanently to your environment is like wearing ski gear everywhere you go just because you occasionally go skiing.
These variables need only be set for the task at hand (building/installing pygraphviz), not for all shell invocations from here on out.

@roskakori
Copy link

That may be but I found setting them globally advantageous if you have multiple projects that use pythongraphviz, if you have to occasionally rebuild your poetry environment from scratch because PyCharm screwed it up, if brew chokes and needs a reinstall every now and then, and if you just try to keep you dev environment up to date without constantly breaking things.

YMMV but I found myself too often looking up how to fix this compile error, and being presented with different search results as time passes but the compile error remains.

But yes, if you have the patience to live with the variables passed to a single call, it's certainly less intrusive.

@RijndertAriese
Copy link

Only thing that worked for me is @bwagner 's final comment after trying dozens of different options. Please add to the install docs for macOS Sonoma.

pip install --no-cache-dir \
  --config-settings="--global-option=build_ext" \
  --config-settings="--global-option=-I$(brew --prefix graphviz)/include/" \
  --config-settings="--global-option=-L$(brew --prefix graphviz)/lib/" \
  pygraphviz

Still works for me! Thaanks!

QuinnyPig added a commit to QuinnyPig/ros2_documentation that referenced this issue Mar 28, 2024
Latest version of pip is needed, as well as a few config flags to show where to find graphviz (pygraphviz/pygraphviz#11 is somehow still helpful / relevant this many years on...)

Signed-off-by: Corey Quinn <[email protected]>
clalancette added a commit to ros2/ros2_documentation that referenced this issue Apr 11, 2024
* Updates for modern macOS dev

Latest version of pip is needed, as well as a few config flags to show where to find graphviz (pygraphviz/pygraphviz#11 is somehow still helpful / relevant this many years on...)

Signed-off-by: Corey Quinn <[email protected]>
Co-authored-by: Chris Lalancette <[email protected]>
mergify bot pushed a commit to ros2/ros2_documentation that referenced this issue Apr 11, 2024
* Updates for modern macOS dev

Latest version of pip is needed, as well as a few config flags to show where to find graphviz (pygraphviz/pygraphviz#11 is somehow still helpful / relevant this many years on...)

Signed-off-by: Corey Quinn <[email protected]>
Co-authored-by: Chris Lalancette <[email protected]>
(cherry picked from commit 1de6ff9)

# Conflicts:
#	source/Installation/Alternatives/macOS-Development-Setup.rst
mergify bot pushed a commit to ros2/ros2_documentation that referenced this issue Apr 11, 2024
* Updates for modern macOS dev

Latest version of pip is needed, as well as a few config flags to show where to find graphviz (pygraphviz/pygraphviz#11 is somehow still helpful / relevant this many years on...)

Signed-off-by: Corey Quinn <[email protected]>
Co-authored-by: Chris Lalancette <[email protected]>
(cherry picked from commit 1de6ff9)

# Conflicts:
#	source/Installation/Alternatives/macOS-Development-Setup.rst
clalancette pushed a commit to ros2/ros2_documentation that referenced this issue Apr 11, 2024
* Updates for modern macOS dev (#4242)

* Updates for modern macOS dev

Latest version of pip is needed, as well as a few config flags to show where to find graphviz (pygraphviz/pygraphviz#11 is somehow still helpful / relevant this many years on...)

Signed-off-by: Corey Quinn <[email protected]>
Co-authored-by: Chris Lalancette <[email protected]>
(cherry picked from commit 1de6ff9)
clalancette pushed a commit to ros2/ros2_documentation that referenced this issue Apr 11, 2024
* Updates for modern macOS dev (#4242)

* Updates for modern macOS dev

Latest version of pip is needed, as well as a few config flags to show where to find graphviz (pygraphviz/pygraphviz#11 is somehow still helpful / relevant this many years on...)

Signed-off-by: Corey Quinn <[email protected]>
Co-authored-by: Chris Lalancette <[email protected]>
(cherry picked from commit 1de6ff9)
@jwhendy
Copy link

jwhendy commented Apr 16, 2024

All of the above looks like workarounds. Does anyone know where this would actually be fixed? If here, why is it closed (I'm happy to open a new issue if helpful). If brew, why put more effort here vs. getting brew to address? I'm also happy to take this up with brew, I just don't have the context to understand why this is a thing/where the root cause lies.

@KSH-KOR
Copy link

KSH-KOR commented Jul 2, 2024

For mac users!!

I solved this issue on mac m1 following the two steps.

  1. Set Environment Variables:
    Open your terminal and set the CPATH and LIBRARY_PATH environment variables:
export CPATH=/opt/homebrew/include
export LIBRARY_PATH=/opt/homebrew/lib
  1. Install pygraphviz:
    Use the following command to install pygraphviz with the specified paths:
    pip install pygraphviz --global-option=build_ext --global-option="-I/opt/homebrew/include" --global-option="-L/opt/homebrew/lib"
  • If you still encounter issues, consider providing the full path to the graphviz directory and specifying it explicitly:
    pip install pygraphviz --global-option=build_ext --global-option="-I/opt/homebrew/include/graphviz" --global-option="-L/opt/homebrew/lib"

@Nish9
Copy link

Nish9 commented Jul 4, 2024

^ This worked for me on m1 mac too, thanks a lot!

@bwagner
Copy link

bwagner commented Jul 7, 2024

Why provide a brittle solution when there's already a functional one? Did you try the previous solution?

Here's why providing -I/opt/homebrew/include and -L/opt/homebrew/lib is an inferior choice to I$(brew --prefix graphviz)/include/ and I$(brew --prefix graphviz)/lib/: When someone uses another than the standard homebrew installation location, your instructions will fail.

In addition, following your instructions causes warnings:

DEPRECATION: --build-option and --global-option are deprecated. pip 24.2 will enforce this behaviour change. A possible replacement is to use --config-settings. Discussion can be found at https://github.com/pypa/pip/issues/11859
WARNING: Implying --no-binary=:all: due to the presence of --build-option / --global-option.
...
WARNING: Ignoring --global-option when building pygraphviz using PEP 517

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests