mlamlamla
mlamlamla

Reputation: 1

Solver GLPK not found in Jupyter Notebook

I am using Windows 10. and MS Visual Studio code 1.94.2. I created a new virtual environment using venv, with python 3.13.0.

I further downloaded GLPK and saved it under C:. I added it the system environment as a variable. Using cmd (outside of MS Visual Studio Code) and executing "echo %path%", I find it listed.

Now, I open MS Visual Studio Code and open the terminal, activating the virtual environment. "glpsol --help" is not re-cognized (which is weird --> Q1: why is that?). So I add the path again in the terminal of the virtual environment: "set PATH=%PATH%;C:\glpk-4.65\w64". Now, "glpsol --help" is recognized.

I now install pyomo in the virtual environment, create a Python file, and execute the following code:

    import pandas as pd
    import pyomo.environ as pyo
    import matplotlib.pyplot as plt
    
    model = pyo.ConcreteModel()
    model.x = pyo.Var([1,2], domain=pyo.NonNegativeReals)
    model.OBJ = pyo.Objective(expr = 2*model.x[1] + 3*model.x[2])
    model.Constraint1 = pyo.Constraint(expr = 3*model.x[1] + 4*model.x[2] >= 1)
    
    opt = pyo.SolverFactory("glpk")  # try also 'cbc', 'glpk', 'gurobi'
    log = opt.solve(model, tee=True)

--> Works well.

Now, I create a Jupyter notebook, same environment, and execute the same code. It does not work. Executing "!echo %path%" in the Jupyter notebook does not show the glpk path.

"!set PATH=%path%;C:\glpk-4.65\w64" does not change the path variable. "!C:/glpk-4.65/w64/glpsol --help" works, "!glpsol --help" does not (Error: cannot be found). "log = opt.solve(model, tee=True)" gives "WARNING: Could not locate the 'glpsol' executable, which is required for solver 'glpk'".

--> What am I missing?

I tried calling the glpk solver but it is not found.

Upvotes: 0

Views: 65

Answers (0)

Related Questions