Solve All Problems when Installing pygraphviz on Windows 10 in Python

Solve All Problems when Installing pygraphviz on Windows 10 in Python is an error which occurs when the pygraphviz or graphviz installation is faulty.

In this article I am going to help you solve this error and understand the root of the problem, also I am presenting other possible solutions that may work if the main solution does not work for you.

Explaining The Problems which Occur when Installing pygraphviz on Windows 10 in Python

The error happens when you try to install pygraphviz on Windows 10 and/or the jupyter notebook.

First of all, let us check out how the message of the error looks like. Make sure your error message is similar to this. To avoid any confusion with another error.

                                                                       #
ModuleNotFoundError Traceback (most recent call last)
C:\Users\name\Anaconda3\lib\site-packages\networkx\drawing\nx_agraph.py 
in 
pygraphviz_layout(G, prog, root, args)
    254     try:
--> 255         import pygraphviz
    256     except ImportError:
ModuleNotFoundError: No module named 'pygraphviz'
                                                                       #

Bellow we will take care of the error using multiple possible solutions according to your needs.

Solution 1 : perform a step by step installation

One of the tricks one can use to try and solve this error quickly is to follow the instructions bellow.

First of all, make sure to install the MSFT C++ compiler. Follow that by installing Anaconda and graphviz for windows.

Second, locate the search bar in windows and type environment variable.

After clicking the icon, edit the PATH. And Add this to the path :

                                                                       #
C:\Program Files (x86)\Graphviz2.38\bin
                                                                       #

Third, Download pygraphviz-1.3.1-cp34-none-win_amd64.whl.

Use the following command.

                                                                       #
conda create --name digraphs python=3.4 anaconda.
                                                                       #

In order to create a Conda environment with Python.

Run the following command.

                                                                       #
activate digraphs.
                                                                       #

Use the command bellow to install pygraphviz.

                                                                       #
pip install pygraphviz-1.3.1-cp34-none-win_amd64.whl.
                                                                       #

Run the command and then exit the current environment.

                                                                       #
python ./gviz_simple.py.
                                                                       #


The series of commands above should be enough to solve your problem, if that is not the suitable solution you can try the solution bellow.

Solution 2 : try pygraphviz.

In case the solution above does not solve your problem, consider following this complementary solution.

Its easy, just replace graphviz with pygraphviz.

That if you are using a conda environment.

Try the command bellow.

                                                                       #
conda install graphviz pygraphviz -c alubbock
                                                                       #

I hope this solution was enough to solve the issue.

The error above was hard to deal with, I spent hours looking for a proper solution or set of solutions.

Summing-up

This error is solved guys, thank you for reading our article, if you have any other errors make sure to search in our site for a solution, so far we are providing solutions for errors in Python, cheers and keep coding.

If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/