Python does not see pygraphviz

Question:

I have installed pygraphviz using easy_install
But when i launch python i have an error:

>>>import pygraphviz as pgv
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pygraphviz
>>> 

Using Ubuntu 12.04 and gnome-terminal.

Asked By: Sashko Lykhenko

||

Answers:

Assuming that you’re on Ubuntu please look at following steps

  1. sudo apt-get install graphviz libgraphviz-dev pkg-config
  2. Create and activate virtualenv if needed. The commands looks something like sudo apt-get install python-pip python-virtualenv
  3. Run pip install pygraphviz
  4. Run terminal and check by importing and see if it works
Answered By: Sidharth Shah

The quick and easy solution is:

sudo apt-get install -y python-pygraphviz

using pip will also work, but make sure you have graphviz, libgraphviz-dev, and pkg-config already installed.

sudo apt-get install -y graphviz libgraphviz-dev pkg-config python-pip
sudo pip install pygraphviz
Answered By: Sean

Under Ubuntu 15.10+ (ie 2015ish Debian), the quick and easy solution is:

sudo apt-get install python-pygraphviz

Any dependencies are properly pulled by apt.

Answered By: CPBL

On Mac OSX, the following did the trick for me:

pip install graphviz
pip install cgraph
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig 
cd /usr/local/include/graphviz 
sudo ln -s . graphviz 
pip install pygraphviz

[As suggested, fixed typo from previously /urs/local/ to /usr/local/]

Answered By: Bart Theeten

On Mac OSX El Capitan, Bart Theeten’s solution works but there are two things you need to be careful. Initially, make sure that you installed graphviz on your computer. You can use homebrew:

brew install graphviz

Other thing is to make sure you add the path of packages to PYTHONPATH

export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages/
Answered By: Alp Celik

On Ubuntu 14.04, there is a problem in auto detecting graphviz library and include files. If you follow the steps below probably you’ll be safe.

1) sudo apt-get install graphviz libgraphviz-dev pkg-config python-pip
2) pip install pygraphviz --install-option="--include-path=/usr/include/graphviz" --install-option="--library-path=/usr/lib/graphviz/" 
Answered By: Alp Celik

In Colab,

!apt  install  libgraphviz - dev
!pip install pygraphviz

Credits: https://gist.github.com/korakot/a80c04a1945b06e2f4a053f92fecfbf9

Answered By: Lin

I use mac m1, I fix this by this.

#install graphviz first
brew install graphviz

#check your graphviz path   
brew info graphviz

#change to your dir
export GRAPHVIZ_DIR="/usr/local/Cellar/graphviz/<VERSION>" #3.0.0 in my case

#finally run this 
pip install pygraphviz --global-option=build_ext --global-option="-I$GRAPHVIZ_DIR/include" --global-option="-L$GRAPHVIZ_DIR/lib"
Answered By: Yicheng Wang
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.