TemoaProject / temoa

Tools for Energy Model Optimization and Analysis
http://temoacloud.com
GNU General Public License v2.0
84 stars 48 forks source link

[Windows] Unable to run MakeGraphviz.py on Windows machine. #32

Closed samgdotson closed 4 months ago

samgdotson commented 2 years ago

Currently, executing python MakeGraphviz.py from Windows command prompt or PowerShell leads to the following error:

(base) PS C:\Users\samgd\Research\bakery-model\pygen_test> python C:\Users\samgd\research\temoa\data_processing\MakeGraphviz.py -i .\bakery_test_kitchen_01.sqlite
setGraphicOption: updated greyFlag = False and splinevar = False
--------------------------------------
GraphvizDiagramGenerator: connected
setGraphicOption: updated greyFlag = False and splinevar = False
createCompleteInputGraph: started with inp_tech = None and inp_comm = None
createCompleteInputGraph: database fetched successfully
createCompleteInputGraph: creating diagrams
Traceback (most recent call last):
  File "C:\Users\samgd\research\temoa\data_processing\MakeGraphviz.py", line 372, in <module>
    res = graphGen.createCompleteInputGraph()
  File "C:\Users\samgd\research\temoa\data_processing\MakeGraphviz.py", line 362, in createCompleteInputGraph
    self.__generateGraph__(quick_run_dot_fmt, args, outputName, outputFormat)
  File "C:\Users\samgd\research\temoa\data_processing\MakeGraphviz.py", line 53, in __generateGraph__
    call(cmd)
  File "C:\Users\samgd\Anaconda3\lib\subprocess.py", line 339, in call
    with Popen(*popenargs, **kwargs) as p:
  File "C:\Users\samgd\Anaconda3\lib\subprocess.py", line 800, in __init__
    restore_signals, start_new_session)
  File "C:\Users\samgd\Anaconda3\lib\subprocess.py", line 1207, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

This error can be FIXED by adding

    def __generateGraph__(self, dotFormat, dotArgs, outputName, outputFormat):
        dotArgs.update(self.colors)
        with open(outputName + '.dot', 'w') as f:
            f.write(dotFormat % dotArgs)
        cmd = ('dot', '-T' + outputFormat, '-o' + outputName +'.' + outputFormat, outputName+'.dot')
        call(cmd, shell=True)

in MakeGraphviz.py. This change does not affect Linux installations. Pull request to follow.