mckinsey / causalnex

A Python library that helps data scientists to infer causation rather than observing correlation.
http://causalnex.readthedocs.io/
Other
2.24k stars 258 forks source link

Running the tutorial No prog neato in path #122

Closed JK87iab closed 3 years ago

JK87iab commented 3 years ago

Description

Trying out the first tutorial but getting the error No prog neato in path.

from IPython.display import Image
from causalnex.plots import plot_structure, NODE_STYLE, EDGE_STYLE

viz = plot_structure(
    sm,
    graph_attributes={"scale": "0.5"},
    all_node_attributes=NODE_STYLE.WEAK,
    all_edge_attributes=EDGE_STYLE.WEAK)
Image(viz.draw(format='png'))

ValueError                                Traceback (most recent call last)
~\anaconda3\envs\causelnex\lib\site-packages\pygraphviz\agraph.py in _get_prog(self, prog)
   1320         try:  # user must pick one of the graphviz programs...
-> 1321             runprog = self._which(prog)
   1322         except:

~\anaconda3\envs\causelnex\lib\site-packages\pygraphviz\agraph.py in _which(self, name)
   1568                 return match[0]
-> 1569         raise ValueError("No prog %s in path." % name)
   1570 

ValueError: No prog neato in path.

During handling of the above exception, another exception occurred:

Your Environment

Anaconda mac used brew install pygraphviz python 3.8 causelnex 0.10.0

oentaryorj commented 3 years ago

Thanks @JK87iab. This appears to be a dependency issue with pygraphviz though. Did you see any error when you installed pygraphviz? Might also be worth trying:

pip install "causalnex[plot]"
JK87iab commented 3 years ago

No error while executing pip install pygraphviz

Using pip install "causalnex[plot]" results in the same error

oentaryorj commented 3 years ago

I tried to dig the pygraphviz codes here, particularly the _which function:

def _which(self, name):
   """Searches for name in exec path and returns full path"""
   import glob
   import platform

   if platform.system() == "Windows":
       name += ".exe"

   paths = os.environ["PATH"]
   for path in paths.split(os.pathsep):
       match = glob.glob(os.path.join(path, name))
       if match:
           return match[0]
   raise ValueError(f"No prog {name} in path.")

It seems that the neato program cannot be found in the system path. I then looked at the installation guide and, for Mac, the recommendation is to install graphviz via homebrew first, followed by a pip install. So can you perhaps try this:

brew install graphviz
pip install pygraphviz

and see if it works?

oentaryorj commented 3 years ago

Closing this for now. Do let us know if the problem still persists. Thank you.