Casadi solve error: Plugin 'ipopt' is not found

Error:

CasADi - 2023-04-18 08:31:30 WARNING(".../casadi/core/casadi_os.cpp:166: Assertion "handle!=nullptr" failed:
PluginInterface::load_plugin: Cannot load shared library 'libcasadi_nlpsol_ipopt.so': 
   (
    Searched directories: 1. casadipath from GlobalOptions
                          2. CASADIPATH env var
                          3. PATH env var (Windows)
                          4. LD_LIBRARY_PATH env var (Linux)
                          5. DYLD_LIBRARY_PATH env var (osx)
    A library may be 'not found' even if the file exists:
          * library is not compatible (different compiler/bitness)
          * the dependencies are not found
   )
  Tried '/home/runner/Python/venv/lib/python3.10/site-packages/casadi' :
    Error code: libgfortran.so.5: cannot open shared object file: No such file or directory
  Tried '' :
    Error code: libgfortran.so.5: cannot open shared object file: No such file or directory
  Tried '.' :
    Error code: ./libcasadi_nlpsol_ipopt.so: cannot open shared object file: No such file or directory") [.../casadi/core/plugin_interface.hpp:142]
Traceback (most recent call last):
  File "main.py", line 56, in <module>
    sol = opti.solve()  # actual solve
  File "/home/runner/Python/venv/lib/python3.10/site-packages/casadi/casadi.py", line 47648, in solve
    return _casadi.Opti_solve(self, *args)
RuntimeError: Error in Opti::solve [OptiNode] at .../casadi/core/optistack.cpp:157:
.../casadi/core/plugin_interface.hpp:292: Plugin 'ipopt' is not found.

Steps to reproduce:

from casadi import *

N = 100  # number of control intervals
# https://web.casadi.org/docs/#using-lookup-tables
SpeedLimit = np.asarray([0.6, 0.6, 0.6, 1, 1, 1, 1.3, 1.3, 1.3, 1.3])
xgrid = np.linspace(0, 1, 10)
SpeedLimitInterp = casadi.interpolant('SpeedLimitInterp', 'linear', [xgrid],
                                      SpeedLimit)
# print(lut(2.5))

opti = Opti()  # Optimization problem

# ---- decision variables ---------
X = opti.variable(2, N + 1)  # state trajectory
pos = X[0, :]
speed = X[1, :]
U = opti.variable(1, N)  # control trajectory (throttle)
T = opti.variable()  # final time

# ---- objective          ---------
opti.minimize(T)  # race in minimal time

# ---- dynamic constraints --------
f = lambda x, u: vertcat(x[1], u - x[1])  # dx/dt = f(x,u)

dt = T / N  # length of a control interval
for k in range(N):  # loop over control intervals
  # Runge-Kutta 4 integration
  k1 = f(X[:, k], U[:, k])
  k2 = f(X[:, k] + dt / 2 * k1, U[:, k])
  k3 = f(X[:, k] + dt / 2 * k2, U[:, k])
  k4 = f(X[:, k] + dt * k3, U[:, k])
  x_next = X[:, k] + dt / 6 * (k1 + 2 * k2 + 2 * k3 + k4)
  opti.subject_to(X[:, k + 1] == x_next)  # close the gaps

# ---- path constraints -----------
# limit = lambda pos: 1-sin(2*pi*pos)/2
limit = lambda pos: SpeedLimitInterp(pos)
opti.subject_to(speed <= limit(pos))  # track speed limit
opti.subject_to(opti.bounded(0, U, 1))  # control is limited

# ---- boundary conditions --------
opti.subject_to(pos[0] == 0)  # start at position 0 ...
opti.subject_to(speed[0] == 0)  # ... from stand-still
opti.subject_to(pos[-1] == 1)  # finish line at position 1

# ---- misc. constraints  ----------
opti.subject_to(T >= 0)  # Time must be positive

# ---- initial values for solver ---
opti.set_initial(speed, 1)
opti.set_initial(T, 1)

# ---- solve NLP              ------
opti.solver("ipopt")  # set numerical backend
sol = opti.solve()  # actual solve

# ---- post-processing        ------
from pylab import plot, step, figure, legend, show, spy

plot(sol.value(speed), label="speed")
plot(sol.value(pos), label="pos")
plot(limit(sol.value(pos)), 'r--', label="speed limit")
step(range(N), sol.value(U), 'k', label="throttle")
legend(loc="upper left")

figure()
spy(sol.value(jacobian(opti.g, opti.x)))
figure()
spy(sol.value(hessian(opti.f + dot(opti.lam_g, opti.g), opti.x)[0]))

show()

Please provide the Repl link. We can’t see your code and run your project without it.

https://replit.com/@YesidBello2/Python?s=app