nemocrys / pyelmer

A python interface to Elmer.
GNU General Public License v3.0
56 stars 18 forks source link

ElmerGrid (or elmerSolver) not found from Windows %PATH% variable #1

Closed basteks closed 3 years ago

basteks commented 3 years ago

While trying to execute a pyelmer example, I got an error FileNotFoundError: [WinError 2] from execute.run_elmer_grid. Unfortunately python's subprocess doesn't look into %PATH% variable while trying to run, so I found a little workaround : I decided to look for the executable (ElmerGrid or ElmerSolver depending on the called function) in the %PATH% variable, and replaced

if elmergrid is None:
        # On Windows ElmerGrid.exe is not found once gmsh.initialize() was executed.
        # Try to use abs-path instead.
        if os.path.exists('C:/Program Files/Elmer 8.4-Release/bin/ElmerGrid.exe'):
            elmergrid = 'C:/Program Files/Elmer 8.4-Release/bin/ElmerGrid.exe'
        else:
            elmergrid = 'ElmerGrid'

with

found = False
if elmergrid is None:
    # On Windows ElmerGrid.exe is not found once gmsh.initialize() was executed.
    # Try to use abs-path instead.
    if os.path.exists('C:/Program Files/Elmer 8.4-Release/bin/ElmerGrid.exe'):
        elmergrid = 'C:/Program Files/Elmer 8.4-Release/bin/ElmerGrid.exe'
    else:
        for dir in os.environ.copy()["PATH"].split(';'):
            if os.path.exists(dir+'\\ElmerGrid.exe'):
                elmergrid = dir+'\\ElmerGrid.exe'
                found = True
        if not found:
            elmergrid = 'ElmerSolver'

and of course the same for run_elmer_solver. It seems to do the trick.

arvedes commented 3 years ago

There should be an optional parameter in the execute function that can be alternatively used to provide the executables. In this way you don't need to modify the source code of pyelmer. Best regards Arved