5

I installed graphviz and pygraphviz, when I open a cmd and type

python
import _graphviz

_graphviz can be imported, but when I run a C++ program which will invoke a .py file, there is a line in this .py file which is

import pygraphviz as pgv

Then it will not be able to import _graphviz, it shows the following info:

Traceback (most recent call last):
  File "E:\project\graph\analysis\x64\Debug\gengraph.py", line 1, in <module>
    import pygraphviz as pgv
  File "C:\Program Files\Python27\lib\site-packages\pygraphviz\__init__.py", lin
e 54, in <module>
    from agraph import AGraph, Node, Edge, Attribute, ItemAttribute
  File "C:\Program Files\Python27\lib\site-packages\pygraphviz\agraph.py", line
20, in <module>
    import graphviz as gv
  File "C:\Program Files\Python27\lib\site-packages\pygraphviz\graphviz.py", lin
e 7, in <module>
    import _graphviz
ImportError: No module named _graphviz

Can you help me, any advice is welcome, thank you!

ryan pei
  • 51
  • 1
  • 1
  • 3

2 Answers2

1

What system are you using? I spent a good 4 hours trying to figure it out on Windows but ended up migrating my project to Ubuntu. From what I've learned, it's caused by the program not finding the pygraphviz file. It searches in this sequence on Windows: 1,register; 2,PATH; 3,folders. Some methods availables:

Find the block in setup.py for register and skip it.

Rename folder of pygraphviz installation(remove blanks) and move it to a path without blanks

In Ubuntu, you could simply "sudo easy-install pygraphviz" which worked for me.

tartaruga_casco_mole
  • 1,086
  • 3
  • 21
  • 29
  • The syntax is `sudo easy_install pygraphviz` but yes this also worked for me. Actually I was just about to give up as pip and git installs just kept failing. – snow6oy Feb 16 '16 at 21:26
-1

I got this going with AMD64 like this:

Win 7 AMD64

  • Install MSFT C++ compiler.
  • Install Anaconda for Win AMD64, Python3.
  • Install graphviz for Win.
  • Add C:\Program Files (x86)\Graphviz2.38\bin to your PATH environment variable.
  • Download pygraphviz-1.3.1-cp34-none-win_amd64.whl.
  • Create a Conda environment with Python version 3.4: conda create --name digraphs python=3.4 anaconda.
  • Enter the environment: activate digraphs.
  • Install pygraphviz using pip3: pip install pygraphviz-1.3.1-cp34-none-win_amd64.whl.
  • Run example: python3 ./gviz_simple.py.
  • Exit the environment: deactivate

https://stackoverflow.com/a/45362845/714413

Community
  • 1
  • 1
darkhipo
  • 1,384
  • 1
  • 14
  • 19