Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PNG not generating in Python3 tutorial on Windows machine #147

Open
aw236 opened this issue Oct 8, 2020 · 2 comments
Open

PNG not generating in Python3 tutorial on Windows machine #147

aw236 opened this issue Oct 8, 2020 · 2 comments

Comments

@aw236
Copy link

aw236 commented Oct 8, 2020

I tried to run the code found in:
https://github.com/h2oai/h2o-tutorials/blob/master/tutorials/isolation-forest/interpreting_isolation-forest.ipynb

I tried the code on two different machines and got the same issue:

FileNotFoundError: No such file or directory: './global_surrogate_decision_tree.png'

the problem is generated by the following code:

def generateTreeImage(decision_tree, image_file_path):
    # Download MOJO
    mojo_path = decision_tree.download_mojo(get_genmodel_jar=True)
    directory = os.path.dirname(mojo_path)
    h2o_jar_path = os.path.join(directory, "h2o-genmodel.jar")
    # Create Graphviz file
    gv_file_path = os.path.join(directory, "decision_tree.gv")
    gv_call = " ".join(["java", "-cp", h2o_jar_path, "hex.genmodel.tools.PrintMojo", "--tree 0 -i", mojo_path , "-o", gv_file_path])
    result = subprocess.call(gv_call, shell=True)
    result = subprocess.call(["ls", gv_file_path], shell = False)
    result = subprocess.call(["dot", "-Tpng", gv_file_path, "-o", image_file_path], shell=False)
    result = subprocess.call(["ls",image_file_path], shell = False)
    
    return Image(image_file_path)

generateTreeImage(global_surrogate_dt, "./global_surrogate_decision_tree.png")

I ripped out the guts of the function and ran it line by line as shown below, to try to narrow down the offending line of code:

decision_tree = global_surrogate_dt
mojo_path = decision_tree.download_mojo(get_genmodel_jar=True); mojo_path

I verified that global_surrogate_decision_tree_hex.zip existed at mojo_path.

directory = os.path.dirname(mojo_path); directory
h2o_jar_path = os.path.join(directory, "h2o-genmodel.jar"); h2o_jar_path

I verified that h2o-genmodel.jar existed at h2o_jar_path.

gv_file_path = os.path.join(directory, "decision_tree.gv"); gv_file_path
gv_call = " ".join(["java", "-cp", h2o_jar_path, "hex.genmodel.tools.PrintMojo", "--tree 0 -i", mojo_path , "-o", gv_file_path]); gv_call

The code fails here:

image_file_path = "./global_surrogate_decision_tree.png"
result = subprocess.call(["dot", "-Tpng", gv_file_path, "-o", image_file_path], shell=False); result

and the error message is below:

FileNotFoundError                         Traceback (most recent call last)
<ipython-input-69-7101915e3dd9> in <module>
      1 image_file_path = "./global_surrogate_decision_tree.png"
----> 2 result = subprocess.call(["dot", "-Tpng", gv_file_path, "-o", image_file_path], shell=False); result

~\AppData\Local\Continuum\anaconda2\envs\pyod_iforest\lib\subprocess.py in call(timeout, *popenargs, **kwargs)
    338     retcode = call(["ls", "-l"])
    339     """
--> 340     with Popen(*popenargs, **kwargs) as p:
    341         try:
    342             return p.wait(timeout=timeout)

~\AppData\Local\Continuum\anaconda2\envs\pyod_iforest\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
    852                             encoding=encoding, errors=errors)
    853 
--> 854             self._execute_child(args, executable, preexec_fn, close_fds,
    855                                 pass_fds, cwd, env,
    856                                 startupinfo, creationflags, shell,

~\AppData\Local\Continuum\anaconda2\envs\pyod_iforest\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
   1305             # Start the process
   1306             try:
-> 1307                 hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
   1308                                          # no special security
   1309                                          None, None,

FileNotFoundError: [WinError 2] The system cannot find the file specified

I checked the directory and indeed, I could not find the file: global_surrogate_decision_tree.png. Not sure if there is an obvious solution here but I think the tutorial should be updated such that this issue doesn't happen for others who may try it.

@Alex-Wenner-FHR
Copy link

Was this ever resolved? I am having the same issue... I tried creating the file in the directory as well and am still not having luck. However, it is very possible that I did create this file in the wrong directory. I am unsure, please help!

@UtkarshaGupte
Copy link

When I ran the above commands, I found that the command "dot" was not recognised:
java -cp h2o-genmodel.jar hex.genmodel.tools.PrintMojo --tree 0 -i surrogate_hex.zip -o gv_file.gv
dot -Tpng gv_file.gv -o decision_tree.png

To make this work, I added the path for Graphviz bin folder in my system and user env variables and it worked (Ref - https://bobswift.atlassian.net/wiki/spaces/GVIZ/pages/20971549/How+to+install+Graphviz+software)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants