Registry / data / pydotplus

pydotplus

JSON →
library2.0.2pypypi✓ verified 89d ago

PyDotPlus is a Python interface to Graphviz's Dot language, acting as an improved version of the original `pydot` project. It allows users to programmatically create, read, and manipulate graphs defined in the DOT language and render them into various image formats using Graphviz. The current version is 2.0.2, with its last release in December 2014, indicating a maintenance rather than active development cadence.

pip install pydotplus
INSTALL
IMPORT
SIG · PYDOTPLUS
P
pydotplus
datapythonv2.0.2
Install
2.6s avg
Import
295ms
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v2.0.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.312s · 20.3MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 2.6s · import 0.279s · 21MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Dot
✓ import pydotplus graph = pydotplus.Dot()
✗ from pydotplus import Dot
While direct import is possible, `import pydotplus` and using `pydotplus.Dot()` is the most common and robust pattern.
graph_from_dot_data
✓ import pydotplus graph = pydotplus.graph_from_dot_data(dot_string)

This quickstart demonstrates how to create a simple directed graph with nodes and edges using `pydotplus` and then attempts to render it to a PNG image. It also includes an example of loading a graph from a DOT string. **Crucially, for the rendering step to succeed, Graphviz must be installed on your system and its `bin` directory must be added to your system's PATH environment variable.**

import pydotplus import os # Create a directed graph graph = pydotplus.Dot(graph_type='digraph') # Add nodes node_a = pydotplus.Node("A", style="filled", fillcolor="red") node_b = pydotplus.Node("B", style="filled", fillcolor="green") node_c = pydotplus.Node("C", style="filled", fillcolor="blue") graph.add_node(node_a) graph.add_node(node_b) graph.add_node(node_c) # Add edges edge_ab = pydotplus.Edge("A", "B", label="connects") edge_bc = pydotplus.Edge("B", "C", arrowhead="open") graph.add_edge(edge_ab) graph.add_edge(edge_bc) # Try to save the graph to a file try: # This requires Graphviz to be installed and its executables in the system PATH output_file = "simple_graph.png" graph.write_png(output_file) print(f"Graph '{output_file}' created successfully.") except pydotplus.graphviz.InvocationException as e: print(f"Error: Graphviz executables not found or not in PATH. {e}") print("Please install Graphviz (https://graphviz.org/download/) and add its 'bin' directory to your system's PATH environment variable.") print("For example, on Windows: ';C:\Program Files (x86)\Graphviz2.38\bin' should be added to PATH.") print("On Linux/macOS, ensure Graphviz is installed via package manager and 'dot' command is accessible.") except Exception as e: print(f"An unexpected error occurred: {e}") # Example of loading from DOT data dot_data = "digraph { A -> B; B -> C; }" loaded_graph = pydotplus.graph_from_dot_data(dot_data) # loaded_graph.write_svg("loaded_graph.svg") # Uncomment to save
Debug
Known issues
breakingGraphviz must be installed separately and its executables must be in your system's PATH environment variable. Failure to do so will result in `pydotplus.graphviz.InvocationException: GraphViz's executables not found` when attempting to render graphs.
fix
Download and install Graphviz from https://graphviz.org/download/. After installation, add the path to its 'bin' directory (e.g., `C:\Program Files\Graphviz\bin` on Windows or `/usr/local/bin/` on macOS/Linux if installed via Homebrew/apt) to your system's PATH environment variable. Restart your terminal/IDE after modifying PATH.
affects: All versions
gotchaWhen running on Windows, if the Graphviz installation path contains spaces (e.g., `C:\Program Files (x86)\Graphviz...`), you might encounter `InvocationException: 'C:\Program' is not recognized as an internal or external command`. This is due to how subprocesses handle unquoted paths.
fix
Ensure the Graphviz installation path added to your PATH environment variable is properly quoted if it contains spaces, or ideally, install Graphviz to a path without spaces (e.g., `C:\Graphviz`). Alternatively, some users report success by modifying `pydotplus`'s internal `graphviz.py` to add quotes around executable paths, but this is a hacky solution.
affects: All versions, primarily Windows users
gotchaConfusion between `pydot` and `pydotplus` is common. `pydotplus` was created as an actively maintained fork to address issues in `pydot`, particularly Python 3 compatibility and `pyparsing` version support, during a period when `pydot` development was stalled.
fix
If starting a new project or migrating, prefer `pydotplus` for better Python 3 compatibility. Ensure you only install one of them to avoid potential conflicts in import paths or runtime behavior, although they typically import as `pydotplus` and `pydot` respectively.
affects: Users transitioning from or concurrently using `pydot`
Errors
Common errors & fixes
GraphViz's executables not found
PyDotPlus is a Python wrapper for Graphviz. This error indicates that the underlying Graphviz executables (like `dot`) are either not installed on your system or their location is not added to your system's PATH environment variable, preventing pydotplus from calling them.
fix
1. Install Graphviz: Download and install Graphviz from its official website (graphviz.org/download/).
2. Add to PATH: Ensure the directory containing Graphviz executables (e.g., C:\Program Files\Graphviz\bin on Windows or /usr/local/bin on Linux/macOS) is added to your system's PATH environment variable. You might need to restart your terminal or IDE for changes to take effect.
3. (Optional, in-script fix for Windows paths with spaces): If Graphviz is in a path with spaces (like 'C:\Program Files'), you can sometimes explicitly set the path in your script:
   ```python
   import os
   os.environ["PATH"] += os.pathsep + 'C:\\Program Files\\Graphviz\\bin'
   import pydotplus
   ```
ModuleNotFoundError: No module named 'pydotplus'
The `pydotplus` Python package has not been installed in the Python environment you are currently using, or there's a conflict with multiple Python installations.
fix
Install the package using pip: `pip install pydotplus`. If using a Jupyter Notebook or similar, try `%pip install pydotplus` or `!pip install pydotplus`. If you have multiple Python versions, ensure you are installing it for the correct Python interpreter (e.g., `python3 -m pip install pydotplus`).
AttributeError: module 'pydotplus' has no attribute 'graph_from_dot_data'
The `graph_from_dot_data` function is not directly available under the top-level `pydotplus` module. It resides within the `pydotplus.graphviz` submodule.
fix
Access the function through its correct module path: `pydotplus.graphviz.graph_from_dot_data()`.
   ```python
   import pydotplus
   graph = pydotplus.graphviz.graph_from_dot_data('digraph {a -> b}')
   ```
InvocationException: Program terminated with status: 1. stderr follows: 'C:\Program' is not recognized as an internal or external command, operable program or batch file.
This specific `InvocationException` typically occurs on Windows when the Graphviz installation path includes spaces (e.g., 'C:\Program Files'), and pydotplus fails to properly quote the path when calling the Graphviz executables, leading to the command-line interpreter misinterpreting the path.
fix
Explicitly add the Graphviz `bin` directory to the PATH environment variable within your Python script, making sure to escape backslashes correctly. This often resolves the quoting issue.
   ```python
   import os
   # Replace with your actual Graphviz bin path
   graphviz_bin_path = 'C:\\Program Files\\Graphviz\\bin'
   os.environ["PATH"] += os.pathsep + graphviz_bin_path
   import pydotplus
   # Your pydotplus code here
   ```
   Alternatively, install Graphviz to a path without spaces if possible.
Upgrade
Version history
2.0.2latest on PyPI · released Dec 9, 2014
Audit
Dependencies
pyparsingrequiredRequired for parsing DOT files. Automatically installed with pydotplus.
GraphvizrequiredExternal software required for rendering graphs into image formats (PNG, SVG, PDF, etc.). Must be installed separately and its executables added to system PATH.
Agent activity
16 hits · last 30 days
node
12
OpenAI (training)
2
Amazon
1
Resources
pydotplus — pip install pydotplus · libregistry