{"id":6799,"library":"pygraphviz","title":"PyGraphviz","description":"PyGraphviz is a Python interface to the Graphviz graph layout and visualization package. It enables users to create, edit, read, write, and draw graphs using Python by accessing Graphviz's graph data structure and layout algorithms. It offers a programming interface similar to NetworkX. The current stable version is 1.14, with minor releases typically occurring a few times a year, alongside less frequent major version updates.","status":"active","version":"1.14","language":"en","source_language":"en","source_url":"https://github.com/pygraphviz/pygraphviz","tags":["graph visualization","graph theory","graphviz","network analysis","data visualization"],"install":[{"cmd":"pip install pygraphviz","lang":"bash","label":"Standard pip installation (requires Graphviz C library)"},{"cmd":"sudo apt-get install graphviz graphviz-dev\npip install pygraphviz","lang":"bash","label":"Ubuntu/Debian with Graphviz"},{"cmd":"brew install graphviz\npip install pygraphviz","lang":"bash","label":"macOS (Homebrew) with Graphviz"}],"dependencies":[{"reason":"PyGraphviz is a wrapper around the Graphviz C library, which must be installed separately on your system. Version 2.46 or later is required for PyGraphviz 1.7+ and recommended for 1.11+.","package":"Graphviz (C library)","optional":false},{"reason":"Required to compile the PyGraphviz Python wrapper. (e.g., build-essential on Linux, Xcode Command Line Tools on macOS, Visual C++ Build Tools on Windows).","package":"C/C++ Compiler","optional":false},{"reason":"Additional development headers and utilities often required for successful compilation on Linux distributions.","package":"python3-dev, libgraphviz-dev, pkg-config","optional":true}],"imports":[{"note":"AGraph is the primary class for graph objects and is typically imported directly or via 'import pygraphviz as pgv; pgv.AGraph()'.","wrong":"import pygraphviz.AGraph","symbol":"AGraph","correct":"from pygraphviz import AGraph"}],"quickstart":{"code":"import pygraphviz as pgv\n\n# Create a directed graph\nG = pgv.AGraph(directed=True, strict=False)\n\n# Add nodes\nG.add_node('A', shape='box', color='red')\nG.add_node('B', shape='circle')\nG.add_node('C', label='Node C')\n\n# Add edges\nG.add_edge('A', 'B', label='connects', penwidth=2)\nG.add_edge('B', 'C', color='blue', style='dashed')\nG.add_edge('C', 'A')\n\n# Set graph attributes\nG.graph_attr['label'] = 'My Sample Graph'\nG.graph_attr['overlap'] = 'false'\nG.graph_attr['splines'] = 'true'\n\n# Layout the graph (using dot engine by default)\n# and draw to a file\nG.layout(prog='dot')\noutput_filename = 'sample_graph.png'\nG.draw(output_filename)\n\nprint(f\"Graph saved to {output_filename}\")\n# print(G) # Uncomment to see the DOT language representation","lang":"python","description":"This quickstart demonstrates how to create a directed graph, add nodes and edges with attributes, set global graph attributes, lay out the graph using a specified engine (e.g., 'dot'), and render it to a PNG image file."},"warnings":[{"fix":"Review the PyGraphviz 0.32+ documentation and API for the new methods and object structures. The API became similar to NetworkX.","message":"PyGraphviz 0.32 introduced significant API changes, being a rewrite not backward compatible with earlier versions (e.g., 0.2x). Programs written for older versions will not work without modification.","severity":"breaking","affected_versions":"<0.32 to >=0.32"},{"fix":"Install the Graphviz C library using your system's package manager (e.g., `sudo apt-get install graphviz graphviz-dev` on Debian/Ubuntu, `brew install graphviz` on macOS) or via official installers for Windows. Ensure Graphviz binaries and libraries are on your system's PATH.","message":"The Graphviz C library (not the Python `graphviz` package) is a mandatory prerequisite and must be installed separately on your operating system *before* installing `pygraphviz`. Failure to do so typically results in `ImportError: libagraph.so.1: cannot open shared object file` or similar compilation errors during `pip install`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Follow the detailed Windows installation instructions in the official PyGraphviz documentation, including installing Visual C++ Build Tools and potentially using `pip install --config-settings` to point to Graphviz directories. Consider using conda or official Graphviz binaries.","message":"Installing PyGraphviz on Windows can be particularly challenging. It often requires specific Graphviz versions (e.g., 2.46+ for PyGraphviz 1.7+), a C/C++ compiler (like Visual C++ Build Tools), and potentially manually specifying Graphviz include and library paths during `pip install` using `--config-settings`.","severity":"gotcha","affected_versions":"All versions on Windows"},{"fix":"Always check the `requires_python` metadata on PyPI or the official documentation for compatibility with your Python version. Upgrade Python if necessary or use an older PyGraphviz version compatible with your environment.","message":"PyGraphviz regularly drops support for older Python versions. For example, PyGraphviz 1.14 dropped Python 3.8 support. PyGraphviz 1.9 dropped Python 3.7, and 1.7 dropped 3.6.","severity":"breaking","affected_versions":"Various, check release notes"},{"fix":"Ensure your system's Graphviz C library installation meets or exceeds the minimum version specified in the PyGraphviz documentation. Upgrade Graphviz if it's too old.","message":"Specific minimum Graphviz C library versions are required by newer PyGraphviz releases. For instance, PyGraphviz 1.7 requires Graphviz 2.46.0 or higher, and PyGraphviz 1.11 also requires Graphviz 2.46+.","severity":"breaking","affected_versions":"PyGraphviz >= 1.7"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}