Skip to content

Commit eb845d8

Browse files
authored
fix: more robust solver installed check (#353)
1 parent 76ab382 commit eb845d8

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

linopy/solvers.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@
4949
which = "where" if os.name == "nt" else "which"
5050

5151
# the first available solver will be the default solver
52-
with contextlib.suppress(ImportError):
52+
with contextlib.suppress(ModuleNotFoundError):
5353
import gurobipy
5454

5555
available_solvers.append("gurobi")
56-
with contextlib.suppress(ImportError):
56+
with contextlib.suppress(ModuleNotFoundError):
5757
_new_highspy_mps_layout = None
5858
import highspy
5959

@@ -72,19 +72,22 @@
7272
if sub.run([which, "cbc"], stdout=sub.DEVNULL, stderr=sub.STDOUT).returncode == 0:
7373
available_solvers.append("cbc")
7474

75-
with contextlib.suppress(ImportError):
75+
with contextlib.suppress(ModuleNotFoundError):
7676
import pyscipopt as scip
7777

7878
available_solvers.append("scip")
79-
with contextlib.suppress(ImportError):
79+
80+
with contextlib.suppress(ModuleNotFoundError):
8081
import cplex
8182

8283
available_solvers.append("cplex")
83-
with contextlib.suppress(ImportError):
84+
85+
with contextlib.suppress(ModuleNotFoundError):
8486
import xpress
8587

8688
available_solvers.append("xpress")
87-
with contextlib.suppress(ImportError):
89+
90+
with contextlib.suppress(ModuleNotFoundError):
8891
import mosek
8992

9093
with contextlib.suppress(mosek.Error):
@@ -95,11 +98,12 @@
9598

9699
available_solvers.append("mosek")
97100

98-
with contextlib.suppress(ImportError):
101+
with contextlib.suppress(ModuleNotFoundError):
99102
import mindoptpy
100103

101104
available_solvers.append("mindopt")
102-
with contextlib.suppress(ImportError):
105+
106+
with contextlib.suppress(ModuleNotFoundError):
103107
import coptpy
104108

105109
with contextlib.suppress(coptpy.CoptError):

0 commit comments

Comments
 (0)