15

I'm having trouble while installing PyGraphviz. I'm using Anaconda in Mac OS X.

Error messages indicates some reasons, but I already checked out it is installed in anaconda directory.

Sundongui-MacBook-Pro:site-packages sundong$ pwd
/Users/sundong/anaconda/lib/python2.7/site-packages
Sundongui-MacBook-Pro:site-packages sundong$ pip install graphviz --upgrade
Requirement already up-to-date: graphviz in /Users/sundong/anaconda/lib/python2.7/site-packages

According to the error messages, How can I change the the include_dirs and library_dirs variables in setup.py??

Here is the error message that I meet

Sundongui-MacBook-Pro:anaconda sundong$ pip install pygraphviz
Collecting pygraphviz
  Using cached pygraphviz-1.3.1.tar.gz
Building wheels for collected packages: pygraphviz
  Running setup.py bdist_wheel for pygraphviz
  Complete output from command /Users/sundong/anaconda/bin/python -c "import setuptools;__file__='/private/var/folders/p6/rjy4tf353bzfy7gsl5jn_yvc0000gn/T/pip-build-bLb4AR/pygraphviz/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d /var/folders/p6/rjy4tf353bzfy7gsl5jn_yvc0000gn/T/tmpwR_08Dpip-wheel-:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.5-x86_64-2.7
  creating build/lib.macosx-10.5-x86_64-2.7/pygraphviz
  copying pygraphviz/__init__.py -> build/lib.macosx-10.5-x86_64-2.7/pygraphviz
  copying pygraphviz/agraph.py -> build/lib.macosx-10.5-x86_64-2.7/pygraphviz
  copying pygraphviz/graphviz.py -> build/lib.macosx-10.5-x86_64-2.7/pygraphviz
  copying pygraphviz/release.py -> build/lib.macosx-10.5-x86_64-2.7/pygraphviz
  copying pygraphviz/version.py -> build/lib.macosx-10.5-x86_64-2.7/pygraphviz
  creating build/lib.macosx-10.5-x86_64-2.7/pygraphviz/tests
  copying pygraphviz/tests/__init__.py -> build/lib.macosx-10.5-x86_64-2.7/pygraphviz/tests
  copying pygraphviz/tests/test.py -> build/lib.macosx-10.5-x86_64-2.7/pygraphviz/tests
  copying pygraphviz/tests/test_attribute_defaults.py -> build/lib.macosx-10.5-x86_64-2.7/pygraphviz/tests
  copying pygraphviz/tests/test_attributes.py -> build/lib.macosx-10.5-x86_64-2.7/pygraphviz/tests
  copying pygraphviz/tests/test_clear.py -> build/lib.macosx-10.5-x86_64-2.7/pygraphviz/tests
  copying pygraphviz/tests/test_drawing.py -> build/lib.macosx-10.5-x86_64-2.7/pygraphviz/tests
  copying pygraphviz/tests/test_edge_attributes.py -> build/lib.macosx-10.5-x86_64-2.7/pygraphviz/tests
  copying pygraphviz/tests/test_graph.py -> build/lib.macosx-10.5-x86_64-2.7/pygraphviz/tests
  copying pygraphviz/tests/test_html.py -> build/lib.macosx-10.5-x86_64-2.7/pygraphviz/tests
  copying pygraphviz/tests/test_layout.py -> build/lib.macosx-10.5-x86_64-2.7/pygraphviz/tests
  copying pygraphviz/tests/test_node_attributes.py -> build/lib.macosx-10.5-x86_64-2.7/pygraphviz/tests
  copying pygraphviz/tests/test_readwrite.py -> build/lib.macosx-10.5-x86_64-2.7/pygraphviz/tests
  copying pygraphviz/tests/test_string.py -> build/lib.macosx-10.5-x86_64-2.7/pygraphviz/tests
  copying pygraphviz/tests/test_subgraph.py -> build/lib.macosx-10.5-x86_64-2.7/pygraphviz/tests
  copying pygraphviz/tests/test_unicode.py -> build/lib.macosx-10.5-x86_64-2.7/pygraphviz/tests
  running egg_info
  writing pygraphviz.egg-info/PKG-INFO
  writing top-level names to pygraphviz.egg-info/top_level.txt
  writing dependency_links to pygraphviz.egg-info/dependency_links.txt
  warning: manifest_maker: standard file '-c' not found

  reading manifest file 'pygraphviz.egg-info/SOURCES.txt'
  reading manifest template 'MANIFEST.in'
  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.5-x86_64-2.7/pygraphviz
  copying pygraphviz/graphviz_wrap.c -> build/lib.macosx-10.5-x86_64-2.7/pygraphviz
  running build_ext
  building 'pygraphviz._graphviz' extension
  creating build/temp.macosx-10.5-x86_64-2.7
  creating build/temp.macosx-10.5-x86_64-2.7/pygraphviz
  gcc -fno-strict-aliasing -I/Users/sundong/anaconda/include -arch x86_64 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/sundong/anaconda/include/python2.7 -c pygraphviz/graphviz_wrap.c -o build/temp.macosx-10.5-x86_64-2.7/pygraphviz/graphviz_wrap.o
  pygraphviz/graphviz_wrap.c:2954:10: fatal error: 'graphviz/cgraph.h' file not found
  #include "graphviz/cgraph.h"
           ^
  1 error generated.
  error: command 'gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for pygraphviz
Failed to build pygraphviz
Installing collected packages: pygraphviz
  Running setup.py install for pygraphviz
    Complete output from command /Users/sundong/anaconda/bin/python -c "import setuptools, tokenize;__file__='/private/var/folders/p6/rjy4tf353bzfy7gsl5jn_yvc0000gn/T/pip-build-bLb4AR/pygraphviz/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/p6/rjy4tf353bzfy7gsl5jn_yvc0000gn/T/pip-qgosXm-record/install-record.txt --single-version-externally-managed --compile:
    running install
    Trying pkg-config
    Failed to find pkg-config
    Trying dotneato-config
    Failed to find dotneato-config
    Failed to find dotneato-config

    Your Graphviz installation could not be found.

            1) You don't have Graphviz installed:
               Install Graphviz (http://graphviz.org)

            2) Your Graphviz package might incomplete.
               Install the binary development subpackage (e.g. libgraphviz-dev or similar.)

            3) You are using Windows
               There are no PyGraphviz binary packages for Windows but you might be
               able to build it from this source.  See
               http://networkx.lanl.gov/pygraphviz/reference/faq.html

            If you think your installation is correct you will need to manually
            change the include_dirs and library_dirs variables in setup.py to
            point to the correct locations of your graphviz installation.

            The current setting of library_dirs and include_dirs is:
    library_dirs=None
    include_dirs=None

    error: Error locating graphviz.

    ----------------------------------------
Command "/Users/sundong/anaconda/bin/python -c "import setuptools, tokenize;__file__='/private/var/folders/p6/rjy4tf353bzfy7gsl5jn_yvc0000gn/T/pip-build-bLb4AR/pygraphviz/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/p6/rjy4tf353bzfy7gsl5jn_yvc0000gn/T/pip-qgosXm-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/p6/rjy4tf353bzfy7gsl5jn_yvc0000gn/T/pip-build-bLb4AR/pygraphviz

5 Answers 5

14

brew install graphviz

then:

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

Both path in bold should NOT contain "graphviz".

https://github.com/pygraphviz/pygraphviz/issues/100#issuecomment-237560404

Worked for me on OSX 10.14.1

3
  • Verified to work on OS X 10.14.5 (Mojave) on 8 June 2019. Thanks!
    – fiacre
    Commented Jun 8, 2019 at 20:47
  • Worked on OSX 10.13.6 and pygraphviz 1.6 Commented Nov 6, 2020 at 14:55
  • For me it was pip install --global-option=build_ext --global-option="-IC:/usr/local/include/" --global-option="-LC:/usr/local/lib/" pygraphviz with pygraphviz 1.9, OS X 12.5 (Monterey), Graphviz installed via homebrew. See also pygraphviz.github.io/documentation/stable/install.html (you just have to change the paths) Commented Aug 7, 2022 at 4:45
7

Assuming that you've already installed graphviz software:

As described in this blog post use the following parameters whilst trying to run pip install pygraphviz

--install-option="--include-path=/usr/local/include/graphviz/" \
--install-option="--library-path=/usr/local/lib/graphviz"

So the final command would look like pip install pygraphviz --install-option="--include-path=/usr/local/include/graphviz/" --install-option="--library-path=/usr/local/lib/graphviz".

What this does is this explicitly specified where the libraries of the original program (graphviz) exist for the python extension to use. Unfortunately, this doesn't seem to get automatically recognized.

Worked on MacOS Sierra with Python 3.6

2
  • 2
    Minor variation that worked for me MacOS Sierra, Python 2.7+, Graphviz installed with MacPorts: pip install pygraphviz --install-option="--include-path=/opt/local/include/" --install-option="--library-path=/opt/local/lib/graphviz" Commented May 8, 2018 at 16:33
  • 1
    What if I'm using pipenv? Commented Sep 12, 2018 at 11:57
4

try the following (make sure to have anaconda-client installed and updated):

conda install --channel https://conda.anaconda.org/garylschultz pygraphviz
0
2

Graphviz can be installed via homebrew: brew install graphviz.

Then do:

cd  /usr/local/Cellar/graphviz/VERSION/include/graphviz
mkdir graphviz
cp cgraph.h graphviz/

And finally:

pip install graphviz

Tested on Sierra and woks fine.

1
  • Instead of steps 2 and 3, I would rather suggest creating a symbolic link (ln -s . graphviz) instead of duplicating files. Commented Feb 11, 2022 at 8:48
0

As of (Mac OS) Ventura, after installing with brew, just run:

python3 -m pip install \
--global-option=build_ext \
--global-option="-I$(brew --prefix graphviz)/include/" \
--global-option="-L$(brew --prefix graphviz)/lib/" \
pygraphviz
2
  • The --global-option flag is now deprecated (per github.com/pypa/pip/issues/11859). Would you be able to please convert your code to the new format (probably using --config-settings)?
    – caleb531
    Commented May 19, 2023 at 2:25
  • 1
    it should be like this python3 -m pip install --config-settings \ "build_ext:--global-option=-I$(brew --prefix graphviz)/include/ --global-option=-L$(brew --prefix graphviz)/lib/" \ pygraphviz Commented May 20, 2023 at 22:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.