Tuesday, January 25, 2022

Install pygraphviz on Windows

I wanted to install python package pygraphiz on Windows. However, I encountered an error, as shown below,


C:> python -m pip  install pygraphviz
python -m pip  install pygraphviz
Collecting pygraphviz
  Using cached pygraphviz-1.8.zip (119 kB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: pygraphviz
  Building wheel for pygraphviz (setup.py) ... error
  ERROR: Command errored out with exit status 1:
  ...
  ...
  ...
  pygraphviz/graphviz_wrap.c(2711): fatal error C1083: Cannot open include file: 'graphviz/cgraph.h': No such file or directory
  ...
  ...
  ...

Clearly, the problem is that pip cannot locate the graphviz's header files. Given that I have already installed Graphviz, I reran the pip command as follows, and it solved the problem.


set GRAPHVIZPATH=C:\Applications\Graphviz\Graphviz2.50
python -m pip install --global-option=build_ext --global-option="-I%GRAPHVIZPATH%\include" --global-option="-L%GRAPHVIZPATH%\lib" pygraphviz

In the above, we provide pip with the location of the include files and the library files. Note that it shows that I had graphviz installed at C:\Applications\Graphviz\Graphviz2.50, which should be adjusted according to your set up.

No comments:

Post a Comment