The Pain, errr, Joy of Getting GraphViz to Work in VSCode (Windows 11)

PATRICK
3 min readDec 27, 2024

--

This was something I had created (Dec 2023) on another site of mine but neglected to share it here…

UPDATED (Dec 27, 2024) : for classifier UserWarning — at the end below — also NOTE: This all works in Jupyter Notebook as well.

After hours of scouring multiple sites (such as stackexchange — the one you cannot be kind to others by giving them props for something you were looking for — I did not want to use this site but not many sites had answers — this was one of the sites, also, with no solid answer) in getting GraphViz to work in VSCode. So many sites had old, invalid answers. There was just no solid, clear direction on this but I saw that there were a LOT of folks looking for a viable answer.

By the way, for folks who do not know what GraphViz is for, it is for the dot product results of training/testing a Machine Learning (ML) model — used to visualize a graph — a data tree from the models’ results.

Instead of working on my Python and Machine Learning studies, I dug in to get an answer that worked for the rest of us. Here are a couple of the primary answers (no longer valid) being spread around the ‘Net for the past few years:

  • Graphviz (dot) language support for Visual Studio Code — by Stephanvs
    or the
  • graphviz — by Joao Pinto — but…. unfortunately, that one is no longer available as an extension

Sadly, neither of those two worked… Here is a process, best option I found was to use the

  • graphviz preview by EFanZH on the marketplace visualstudio site

So, after — and after exiting VSCode, did the following:

a) Installed GraphViz (for all users)

  • either directly from the marketplace or via the
  • VSCode extension install method — I prefer the direct install for this one… but….
  • powershell install is another way using ===>> winget install graphviz

b) in powershell, verified it was up with dot -V

c) edited the system PATHs (both of them) in environmental variables, using: C:\Program Files\Graphviz & C:\Program Files\Graphviz\bin for both PATH sections

d) restarted the PC (just in case)

e) opened VSCode

There it is…

Just remember to install the necessary libraries/packages in Jupyter Notebook (in the environment or venv you are working in) and the necessary extensions in VSCode…

Another highly useful site for graphviz information: New simplified installation procedure on Windows

.

Now…. just have to go on and get LaTeX (pylatex) installed in my environments to do stuff like yhat and y is a member R, etc., etc., etc…

NOTE: stackexchange is just TOO hyper-moderated for a good conversation… they want to maintain civility (curtail superfluous chit-chat, supposedly….) but when one is not allowed to say ‘thanks to so-so for posting solid content’ — that is a bit much (extreme). I believe in civility and business courtesy and professionalism but this site just goes too far in moderating conversations. It is like doing Trigger Warnings when it is not necessary and the vast majority of adults DO NOT need trigger warnings…

So, if you want to give more than facts/explicit answers, the stackexchange sites are not for you.

And if you are using something like this:
* clf = clf.fit(X, y) ←- using this could cause or causes a warning message:

such as:
* UserWarning: X does not have valid feature names, but RandomForestClassifier was fitted with feature names

Modify your classifier to this:
* clf = RandomForestClassifier(n_estimators=10)
* clf = clf.fit(X.values, y.values)

.

Shortened URL for this page →> http://tinyurl.com/uxn3cssf

.

Tags:

classifier, efanzh, graphviz, graphviz dot, joao pinto, latex, machine learning, ML, powershell, pylatex, Python, stackexchange, stefanvs, userwarning, userwarning for classifier, venv, visual studio, Visual Studio Code, vs code, vscode, win11

--

--

PATRICK
PATRICK

Written by PATRICK

Data Engineer, Cloud Architect, Intelligence & Cyber guy: -- Innovation, Change, Improvement & Equality - 4 ALL! See my ABOUT https://patrick642.wordpress.com/

Responses (1)