Spyder does not find glpsol

2.2k views Asked by At

I use os x 10.11, anaconda 1.3.1, python 3.5, glpk 4.60, pyomo 5.0.1, spyder 3.0.2. If i run a scrip which uses pyomo to call glpk i get the following warning and error:

WARNING:pyomo.solvers:Could not locate the 'glpsol' executable, which is required for solver 'glpk'
ApplicationError: No executable found for solver 'glpk'

If i start the same script via the terminal or a jupyter notebook it runs without a problem.

I installed glpk using:

conda install -c conda-forge glpk=4.60 

How do i get glpk working within the spyder environement?

If i run

which glpsol

i get

/Users/myusername/anaconda/bin/glpsol

but adding the directory into the PYTHONPATH manager within Spyder does not change anything.

Any help is highly appreciated. Thanks

1

There are 1 answers

1
jsiirola On

Pyomo's GLPK interface works by launching glpsol as a separate process. It finds the glpsol executable by searching the PATH environment variable. You need to make sure that the path to glpsol (in your case /Users/myusername/anaconda/bin/) is in the PATH environment variable for the spyder environment. You can do this in a number of ways:

  • [Windows only] it is possible to edit this using Tools-Current user environment variables in the spyder IDE.
  • [Windows only] you can set your user's PATH within Windows (the route to the option varies from version to version, for example, see Windows 7 or Windows 8.1.
  • [Unix/Linux/MacOS] you can edit your shell initialization (e.g., ~/.bashrc for BASH, ~/.cshrc for CSH/TCSH) to set the PATH environment variable there.
  • [within Spyder] you can specify either a couple lines of python code or a small script that adds the directory to the IPython console PATH through the spyder preferences (Tools-Preferences-IPython console-Startup tab. You would want something like:

    import os
    os.environ['PATH'] = os.pathsep.join((os.environ['PATH'], '/Users/myusername/anaconda/bin/'))
    

Note: PATH and PYTHONPATH are not the same: PATH is the executable search path. PYTHONPATH is the search path that Python uses to find importable modules.