Python does not see pygraphviz
Solution 1
Assuming that you're on Ubuntu please look at following steps
sudo apt-get install graphviz libgraphviz-dev pkg-config
- Create and activate virtualenv if needed. The commands looks something like
sudo apt-get install python-pip python-virtualenv
- Run
pip install pygraphviz
- Run terminal and check by importing and see if it works
Solution 2
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/"
Solution 3
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
Solution 4
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/]
Solution 5
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/
Related videos on Youtube
Sashko Lykhenko
BY DAY: PhD student at Institute of molecular biology and genetics Kyiv, Ukraine
Updated on March 30, 2022Comments
-
Sashko Lykhenko about 2 years
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.
-
Sidharth Shah over 11 yearsHave you used virtulenv, if so can you please confirm if the environment on which you installed the package is the same from which you may be calling script or invoking shell?
-
Sashko Lykhenko over 11 yearsI dont know if i have used virtulenv. How to check if i have installed pyhraphviz and python on the same environment?
-
Sashko Lykhenko over 11 yearsI just typed easy_install pyhraphviz
-
Sidharth Shah over 11 yearsOk do the following in your gnoe-terminal 1.
pip install virtualenv
2.virtualenv myenv
3.source myenv/bin/activate
4.pip install pygraphviz
Then run python and tryimport pygraphviz
as check if it works. -
Sidharth Shah over 11 yearsAlso take a look at this nice Tutorial on pip and virtualenv when you have time.
-
Sashko Lykhenko over 11 yearsI dont have pip installed. apt-get does not contain it either. And apt-get does not contain virtualenv
-
Sidharth Shah over 11 yearsTry
sudo apt-get install python-pip python-virtualenv
-
Sashko Lykhenko over 11 yearsAfter "pip install pygraphviz": Command python setup.py egg_info failed with error code 1 in /home/sashko/src/webkit2/webkit/Tools/Scripts/myenv/build/pygraphviz Storing complete log in /home/sashko/.pip/pip.log
-
Sashko Lykhenko over 11 yearsOSError: Error locating graphviz.
-
Sidharth Shah over 11 yearsJust curios did you do
sudo apt-get install graphviz
before you're doingpip install pygraphviz
. In my case I was missing that, on my local VM. -
Sashko Lykhenko over 11 yearsyes, i did sudo apt-get install graphviz before doing pip install pygraphviz.
-
Sashko Lykhenko over 11 yearsHow to find out where "graphviz" was installed? And were it should be installed so that pyhraphviz setup.py could find it?
-
Sidharth Shah over 11 yearsOk I figure the issue. You might be missing libgraphviz-dev. You can install it using
sudo apt-get install libgraphviz-dev
. You can check if graphviz is installed usingdpkg -l | grep 'graphviz'
-
Sashko Lykhenko over 11 yearsWorked! Will it work only in myenv?
-
Sidharth Shah over 11 yearsYes it would. Give it a try.
-
-
Honghe.Wu over 10 yearsYes,
pkg-config
is important, otherwisepip install pygraphviz
will can not be compiled, causelibrary_path
. -
SparkAndShine over 8 years
ImportError: undefined symbol: Agundirected
, as described here. -
CPBL over 8 yearsWhy are these needed? Installing (and using) python-pygraphviz seemed to work fine for me without libgraphviz-dev. Why then is this needed in advance if its not an explicit dependency, and why the others?
-
Sean over 8 yearsthis was answered almost 3 years ago, its possible that they've changed how pygraphviz is packaged by now so that this is not all necessary. If that's the case, you should post an answer here to that effect.
-
Davy over 7 yearsWorked for me in combination with pydot2 installation + but replace in above instructions 'urs' by 'usr'
-
Bretsko about 7 yearsThanks! For me just installing
python-pygraphviz
fixed the problem -
rwenz3l about 7 yearsThanks for this, also works for me on Ubuntu 16.04 LTS when trying to install pygraphz via pip
-
Chris about 6 yearsThese install options also worked for me experiencing the same error on macOS (having run
brew install graphviz
), except the path was/usr/local/include/graphviz
and the lib was/usr/local/lib/graphviz
, so full command was:pip3.6 install pygraphviz --install-option="--include-path=/usr/local/include/graphviz/" --install-option="--library-path=/usr/local/lib/graphviz”
. -
haku over 5 yearsOn Ubuntu 18.04, I could pull it off with just
sudo apt-get install graphviz libgraphviz-dev graphviz-dev
followed bypip install pygraphviz
-
Lucas Aimaretto almost 4 yearsalso works in ubuntu 20.04 LTS. I needed this in order to install it ..
-
sumitkanoje over 3 yearsmake sure you restart your terminal...so your changes gets affected
-
alxlives about 2 yearsThank you for this, was the only solution that worked. Just needed to change
GRAPHVIZ_DIR
to my local HomeBrew path