6
import pygraphviz

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pygraphviz/__init__.py", line 58, in <module>
    from .agraph import AGraph, Node, Edge, Attribute, ItemAttribute, DotError
File "/usr/local/lib/python2.7/dist-packages/pygraphviz/agraph.py", line 26, in <module>
    from . import graphviz as gv
File "/usr/local/lib/python2.7/dist-packages/pygraphviz/graphviz.py", line 28, in <module>
    _graphviz = swig_import_helper()
File "/usr/local/lib/python2.7/dist-packages/pygraphviz/graphviz.py", line 24, in swig_import_helper
    _mod = imp.load_module('_graphviz', fp, pathname, description)
ImportError: /usr/local/lib/python2.7/dist-packages/pygraphviz/_graphviz.so: undefined symbol: Agundirected

I have already tried

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

I have also tried this answer but still not working

Python does not see pygraphviz

5
  • The error is caused by the graphviz library failing to load a dynamic library - check if the library actually exists, and be sure to run ldconfig to update paths to dynamic libraries if the graphviz directory isn't there.
    – MatsLindh
    Oct 1, 2015 at 10:54
  • can you pls help me to check whether actually the library exists?also how to run idconfig
    – midhun j
    Oct 1, 2015 at 11:32
  • @midhunj Use sudo ldconfig. It still doesn't work for me. Oct 2, 2015 at 14:08
  • I have tried ldconfig.Still it is not working.
    – midhun j
    Oct 3, 2015 at 4:12
  • When iam trying to import graphviz, its working fine.Then can any one explain why pygraphviz is not getting imported?
    – midhun j
    Oct 6, 2015 at 10:08

2 Answers 2

12

First of all, uninstall your current module:

 pip uninstall pygraphviz

then check your paths with:

 pkg-config --libs-only-L libcgraph
 pkg-config --cflags-only-I libcgraph

That commands should tell the path to the library, for example:

-I/usr/include/graphviz  

Then, using the path from the above output, run [within your virtualenv] the command:

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

Source: https://github.com/pygraphviz/pygraphviz/issues/71

2
  • install-option twice? Why's that?
    – MERose
    Jan 23, 2017 at 14:06
  • Never mind the output from pkg-config --libs-only-L libcgraph. In my case (Ubuntu 16.04) that command returns an emtpy line, and that is exactly the reason why pip doesn't detect the correct path for the graphviz library. In my case I just installed using: pip install pygraphviz --install-option="--include-path=/usr/include/graphviz" --install-option="--library-path=/usr/lib/graphviz/" and then it worked. Jun 30, 2017 at 14:03
4

On Ubuntu 14.04 @Martin0x777's answer did not work for me. So I installed pygraphviz from github instructions and the error is gone:

git clone https://github.com/pygraphviz/pygraphviz.git
cd pygraphviz
python setup.py install

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.