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

Community
  • 1
  • 1
midhun j
  • 61
  • 1
  • 4
  • 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 01 '15 at 10:54
  • can you pls help me to check whether actually the library exists?also how to run idconfig – midhun j Oct 01 '15 at 11:32
  • @midhunj Use `sudo ldconfig`. It still doesn't work for me. – SparkAndShine Oct 02 '15 at 14:08
  • I have tried ldconfig.Still it is not working. – midhun j Oct 03 '15 at 04:12
  • When iam trying to import graphviz, its working fine.Then can any one explain why pygraphviz is not getting imported? – midhun j Oct 06 '15 at 10:08

2 Answers2

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

Martin0x777
  • 423
  • 1
  • 3
  • 11
  • `install-option` twice? Why's that? – MERose Jan 23 '17 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. – Augusto Destrero Jun 30 '17 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
Community
  • 1
  • 1
Daniel
  • 2,950
  • 2
  • 25
  • 45