Sashko Lykhenko
Sashko Lykhenko

Reputation: 1654

Python does not see pygraphviz

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.

Upvotes: 59

Views: 79549

Answers (11)

krisgeus
krisgeus

Reputation: 56

For those using poetry this might help

CFLAGS="-I$(brew --prefix graphviz)/include/ -L$(brew --prefix graphviz)/lib/" poetry install

Upvotes: 1

Arslan Mehmood
Arslan Mehmood

Reputation: 1

check the answer here: Installing pygrahviz in google colab

graphviz is installed already, but need lib too

!apt install libgraphviz-dev !pip install pygraphviz

Upvotes: 0

Sebastian Adam
Sebastian Adam

Reputation: 91

This is the only command that worked for me on my M1 MacBook Pro (MacOS 14.2.1):

python3 -m pip install -U --no-cache-dir  \
        --config-settings="--global-option=build_ext" \
        --config-settings="--global-option=-I$(brew --prefix graphviz)/include/" \
        --config-settings="--global-option=-L$(brew --prefix graphviz)/lib/" \
        pygraphviz

Credit to this guy here

Upvotes: 9

Yicheng Wang
Yicheng Wang

Reputation: 171

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"

Upvotes: 17

Lin
Lin

Reputation: 19

In Colab,

!apt  install  libgraphviz - dev
!pip install pygraphviz

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

Upvotes: -1

celikalp
celikalp

Reputation: 241

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/" 

Upvotes: 20

celikalp
celikalp

Reputation: 241

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/

Upvotes: 4

Bart Theeten
Bart Theeten

Reputation: 651

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/]

Upvotes: 16

CPBL
CPBL

Reputation: 4030

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.

Upvotes: 3

Sidharth Shah
Sidharth Shah

Reputation: 1609

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

Upvotes: 141

Sean
Sean

Reputation: 2475

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

Upvotes: 16

Related Questions