How to install 'pygraphviz'?

I'll walk you through the steps that worked for me. The installation process depends on the operating system. I'll show the installation process for package/library pygraphviz on both operating systems, i.e. Windows and macOS.

macOS
Let's first look at the process for the macOS, and you can also check out the official documentation page of the pygraphviz to install it.
https://pygraphviz.github.io/documentation/stable/install.html

  1. Install Python on your system, preferably the latest version. You can download it from the official site
    https://www.python.org/downloads/.
  2. Now let's get started with the installation of the pygraphviz. Before installing the package pygraphviz, we have to install the package called Graphviz.
    Install Graphviz using homebrew, open your terminal and run this command.
  3. Run this command to get the location of the Graphviz we just installed, and copy the location of the file with the version (check the image for the reference)
copy the file location (marked with red ink)

4 . Now, we have to store this path of Graphviz in the environment variable using the following command.

5. Run this command to install pygraphviz. If pip is not working for you, try pip3. You can also check this comment by Gino Mempin on StackOverflow https://stackoverflow.com/a/70439868/19330852.

The above process should successfully install the pygraphviz for you in macOS. If this process fails, you can carefully go through the error message to know what's causing the problem and ask your best friend Google about it :)

Windows
For the windows operating system installing the pygraphviz package, I've used Chocolatey (a package manager for windows). Let's get started —

  1. Install Python on your system, preferably the latest version. You can download it from the official site
    https://www.python.org/downloads/.
  2. Install Chocolatey if you don't have it already on your machine. You can visit https://jcutrer.com/windows/install-chocolatey-choco-windows10 to check the detailed steps.
  3. Now, install Graphviz using the command. Again you can check the official site to see this approach. https://pygraphviz.github.io/documentation/stable/install.html . There are other ways to install the package, but the choco method worked for me.
  4. Search for Graphviz as we need the location of this package to install pygraphviz. Most probably, you'll see this folder in your
  5. In windows search, search for edit environment variables, or you can see this in the control panel. Go to the Graphviz folder you got from the previous step and open the folder to find the "bin folder" copy the location ~/your_path/Graphviz/bin.
    In the environment variable, click on the Path variable, click edit and add this location to it.
  6. Let's run the pygraphviz package installer, and you can check this command at the official documentation here, make sure you copy the command under the Chocolatey section.
    https://pygraphviz.github.io/documentation/stable/install.html#id1

If you are facing below error then follow the step [**] and then continue from step 2 in Windows OS section.
error: Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build Tools”: https://visualstudio.microsoft.com/visual-cpp-build-tools/

[**] Follow this site to solve the above error -> https://docs.microsoft.com/en-us/answers/questions/136595/error-microsoft-visual-c-140-or-greater-is-require.html

I hope this helps you install pygraphviz, and if it doesn't, don't worry. There are a bunch of sites with solutions. While solving these issues, I've referred to multiple sites, and reading the error message carefully helped a lot. Rather than the simple steps to install this package, I've faced a lot of trouble resolving this. Anyways, a big Thank you to all those community builders.

See you again on the next blog.

--

--

UI/UX Designer, Software Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store