Repository: networkx/networkx

Issue:
Deprecate pydot?
In https://github.com/networkx/networkx/pull/5721, we added a `PendingDeprecationWarning` for `nx.nx_pydot.*`. It has a number of issues and isn't actively maintained. We are also planning to improve installation issues for pygraphviz. This is a tracking issue to gather feedback from users. 

Please leave a comment if you have feelings either way about this change.


Discussion:
> We are also planning to improve installation issues for pygraphviz.

Do you mean providing wheel package for pygraphviz? I know I had colleagues having trouble building/installing the package on MacOS. That would be awesome!
I looked at the PR mentioned, and it looks like the deprecation warning for `nx.nx_pydot.pydot_layout` doesn't suggest a replacement. Is there a way to use pygraphviz via networkx for generating graph layouts? If not, please don't deprecate yet - those layout generators are seriously useful (e.g. the spring layouts are much better than the native networkx ones, as far as I can tell).
Ah, I see `nx.nx_agraph.pygraphviz_layout` exists - perhaps those could be added to the deprecation message?
On Windows, it's really hard to get pygraphviz to work. I very much prefer a lightweight tool that only outputs a Graphviz dotfile and then lets me run the Graphviz binary from a script to render diagrams from it myself. I'm not sure what the issues with pydot are, but from my perspective as a user, pygraphviz and pydot may overlap somewhat but still fulfill two different needs. If pydot support actually gets removed I'd be SOL wrt network visualization.
Thanks for this comment!
As you may have gathered, our concern with pydot is that it doesn't seem to be maintained anymore. We've started to have bug reports that might just never be fixed.  We've been working pretty hard on getting pygraphviz to be easier to install on Windows. But there are understandable limitations when using a program with such a storied history like Graphviz.

Our support for pydot depends on comments like this one. So thank you.
umh, i just want to render my graph/network from python script to terminal as inline image, how to do that 😅 ?

<!-- anyone has any experience with using mermaid from within python? -->

My trail for reaching here:

* DeprecationWarning: nx.nx_pydot.to_pydot depends on the pydot package, which hasknown issues and is not actively maintained. See https://github.com/networkx/networkx/issues/5723

* https://github.com/pydot/pydot/blob/90936e75462c7b0e4bb16d97c1ae7efdf04e895c/README.md?plain=true#L116
<-- https://www.graphviz.org/resources/#python
<-- https://networkx.org/documentation/stable/reference/drawing.html
<-- https://www.geeksforgeeks.org/visualize-graphs-in-python/
<-- [nwks](https://duckduckgo.com/?q=visualise+networks+in+python&t=vivaldi&ia=web) <-- gfg article <-- [grphs](https://duckduckgo.com/?q=how+to+draw+graphs+in+python&t=vivaldi&ia=web) <-- ddg 🔍 

* https://pypi.org/project/imgcat/
<-- ddg 🔍 : [python iterm2 image protocol](https://duckduckgo.com/?q=python+iterm2+image+protocol&t=vivaldi&ia=web)

----

> [NX's] main goal is to enable graph analysis **rather than perform graph visualization**. In the future, graph visualization functionality **may be removed** from NetworkX or only available as an add-on package. 
Proper graph visualization is hard, and we highly recommend that people visualize their graphs **with tools dedicated** to that task.
> \- [NX/Reference/Drawing](https://networkx.org/documentation/stable/reference/drawing.html)
_hiding myself as offtopic_

----
> I'd be SOL wrt network visualization.

SOL = Simply Out of Luck?

https://www.acronymfinder.com/Slang/SOL.html
Are you saying you want to render the graph in the terminal window? (we have ascii representations of graphs #5602 )

If you mean you want to render the graph from a terminal-based script, we will continue to support `pygraphviz` which creates dot files.  We are definitely not cutting off support for interaction with GraphViz. 

And if you don't need the graphviz features, the matplotlib-based tools we offer will continue in the long term.  So, basic image creation is supported. But we aren't able to support all the features of a full-fledged graph visualization tool.

Perhaps we should update the comments in the NX/Reference/Drawing section to make it more clera that basic rrawing will continue to be available via networkx. :}
> we have ascii representations of graphs #5602

the text based thing is nice, i wanted to experiment with that too. thanks for sharing it.



> Are you saying you want to render the graph in the terminal window?

nope, i was saying that 
- to render an image file from graph (i.e. static image, not in a separate window like `matplotlib.plot.show()` which opens an interactive widget
- the rest of the part is covered thereafter by <tt>[imgcat]</tt> module which you don't have to worry about 😃 

[imgcat]: https://pypi.org/project/imgcat/
oh, i
- missed sharing one part of why i dabbled into weeds of this `networkx.drawing.nx_pydot.to_pydot(my_networkx_graph)` method 

----
_Have shared the following at: https://github.com/networkx/networkx/discussions/6638 . Please add your input related to this over there. Thanks 😃_

<details>

- 'ts that the `ms-python.vscode-pylance` (python LS for VSCode) is showing errors with networkx.draw related functions 

~~(wait, i am getting the details of it)~~ _see below_

> "draw" is not a known member of module "networkx" Pylance [reportGeneralTypeIssues](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportGeneralTypeIssues)
(function) draw: Unknown


> "draw_networkx" is not a known member of module "networkx" Pylance [reportGeneralTypeIssues](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportGeneralTypeIssues)
(function) draw_networkx: Unknown

</details>
I believe matplotlib can save the figure without drawing it interactively.
Maybe use `matplotlib.pyplot.savefig` instead of `matplotlib.pyplot.show`.  There may be other ways too. They definitely allow image file creation without any interactive UI.
Just to put a good word in for leaving pydot around for a while, it works on in-browser systems like Jupyter Lite, whereas pygraphviz would not be possible to use there without [additional effort](https://github.com/pygraphviz/pygraphviz/issues/453) compiling a [WASM version](https://github.com/pygraphviz/pygraphviz/issues/319).
> it works on in-browser systems like Jupyter Lite, whereas pygraphviz would not be possible

This is true since `pydot` is pure Python, though it's worth noting that:
 1) You'd only be able to produce dot files - converting to actual image formats (e.g `.png`) would require graphviz to be installed (not sure how difficult this is for in-browser systems), and
 2) It "works" in the sense that it is installable, but there are many defects related to updates to `pyparsing` that pydot never incorporated as it has been unmaintained for nearly 2 years.
@jarrodmillman  @MridulS  @rossbar A new pydot version has been released which should fix the breaking issues!

I'm not sure what's the current state of pydot in networkx, but I'm just letting you know that if you'd want to bring it back, you could try 😄 

Resolving patch:
diff --git a/networkx/conftest.py b/networkx/conftest.py
--- a/networkx/conftest.py
+++ b/networkx/conftest.py
@@ -89,9 +89,6 @@ def pytest_collection_modifyitems(config, items):
 # TODO: The warnings below need to be dealt with, but for now we silence them.
 @pytest.fixture(autouse=True)
 def set_warnings():
-    warnings.filterwarnings(
-        "ignore", category=DeprecationWarning, message="nx.nx_pydot"
-    )
     warnings.filterwarnings(
         "ignore",
         category=FutureWarning,
diff --git a/networkx/drawing/nx_pydot.py b/networkx/drawing/nx_pydot.py
--- a/networkx/drawing/nx_pydot.py
+++ b/networkx/drawing/nx_pydot.py
@@ -19,7 +19,6 @@
  - Graphviz:      https://www.graphviz.org
  - DOT Language:  http://www.graphviz.org/doc/info/lang.html
 """
-import warnings
 from locale import getpreferredencoding
 
 import networkx as nx
@@ -41,13 +40,6 @@ def write_dot(G, path):
 
     Path can be a string or a file handle.
     """
-    msg = (
-        "nx.nx_pydot.write_dot depends on the pydot package, which has "
-        "known issues and is not actively maintained. Consider using "
-        "nx.nx_agraph.write_dot instead.\n\n"
-        "See https://github.com/networkx/networkx/issues/5723"
-    )
-    warnings.warn(msg, DeprecationWarning, stacklevel=2)
     P = to_pydot(G)
     path.write(P.to_string())
     return
@@ -79,14 +71,6 @@ def read_dot(path):
     """
     import pydot
 
-    msg = (
-        "nx.nx_pydot.read_dot depends on the pydot package, which has "
-        "known issues and is not actively maintained. Consider using "
-        "nx.nx_agraph.read_dot instead.\n\n"
-        "See https://github.com/networkx/networkx/issues/5723"
-    )
-    warnings.warn(msg, DeprecationWarning, stacklevel=2)
-
     data = path.read()
 
     # List of one or more "pydot.Dot" instances deserialized from this file.
@@ -120,12 +104,6 @@ def from_pydot(P):
     >>> G = nx.Graph(nx.nx_pydot.from_pydot(A))
 
     """
-    msg = (
-        "nx.nx_pydot.from_pydot depends on the pydot package, which has "
-        "known issues and is not actively maintained.\n\n"
-        "See https://github.com/networkx/networkx/issues/5723"
-    )
-    warnings.warn(msg, DeprecationWarning, stacklevel=2)
 
     if P.get_strict(None):  # pydot bug: get_strict() shouldn't take argument
         multiedges = False
@@ -220,13 +198,6 @@ def to_pydot(N):
     """
     import pydot
 
-    msg = (
-        "nx.nx_pydot.to_pydot depends on the pydot package, which has "
-        "known issues and is not actively maintained.\n\n"
-        "See https://github.com/networkx/networkx/issues/5723"
-    )
-    warnings.warn(msg, DeprecationWarning, stacklevel=2)
-
     # set Graphviz graph type
     if N.is_directed():
         graph_type = "digraph"
@@ -348,14 +319,6 @@ def graphviz_layout(G, prog="neato", root=None):
     -----
     This is a wrapper for pydot_layout.
     """
-    msg = (
-        "nx.nx_pydot.graphviz_layout depends on the pydot package, which has "
-        "known issues and is not actively maintained. Consider using "
-        "nx.nx_agraph.graphviz_layout instead.\n\n"
-        "See https://github.com/networkx/networkx/issues/5723"
-    )
-    warnings.warn(msg, DeprecationWarning, stacklevel=2)
-
     return pydot_layout(G=G, prog=prog, root=root)
 
 
@@ -399,12 +362,6 @@ def pydot_layout(G, prog="neato", root=None):
     """
     import pydot
 
-    msg = (
-        "nx.nx_pydot.pydot_layout depends on the pydot package, which has "
-        "known issues and is not actively maintained.\n\n"
-        "See https://github.com/networkx/networkx/issues/5723"
-    )
-    warnings.warn(msg, DeprecationWarning, stacklevel=2)
     P = to_pydot(G)
     if root is not None:
         P.set("root", str(root))


Test patch:
diff --git a/networkx/drawing/tests/test_pydot.py b/networkx/drawing/tests/test_pydot.py
--- a/networkx/drawing/tests/test_pydot.py
+++ b/networkx/drawing/tests/test_pydot.py
@@ -11,7 +11,6 @@
 pydot = pytest.importorskip("pydot")
 
 
-@pytest.mark.xfail
 class TestPydot:
     def pydot_checks(self, G, prog):
         """