Skip to content

Commit

Permalink
try more exhaustive search
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 committed Dec 8, 2024
1 parent 67ff753 commit 4fbea3c
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,37 @@
# look for various gurobi versions, which are annoyingly
# suffixed with the version number, and wildcards don't work


def find_conda_gurobi() -> tuple[str, str] | tuple[None, None]:
conda_prefix = os.environ.get("CONDA_PREFIX")
if not conda_prefix:
raise RuntimeError(
"No active Conda environment found. Activate an environment before running."
)

# Construct the potential library paths
library_paths = [
os.path.join(conda_prefix, "Library", "bin"), # Windows DLLs
os.path.join(conda_prefix, "lib"), # macOS/Linux
]

for lib_path in library_paths:
if os.path.exists(lib_path):
os.environ["PATH"] += os.pathsep + lib_path # Dynamically add to PATH

# Search for Gurobi in the active Conda environment
for v, prefix in product(range(100, 150, 10), ("lib", "")):
gurobi_lib = f"{prefix}gurobi{v}"
if found := util.find_library(gurobi_lib):
return gurobi_lib, found

return (None, None)


for v, prefix in product(range(100, 150, 10), ("lib", "")):
GUROBI_LIB = f"{prefix}gurobi{v}"
if (gurolib := util.find_library(GUROBI_LIB)) is not None:
print("FOUND GUROBI library: ", gurolib)
GUROBI_LIB, lib_path = find_conda_gurobi()
if GUROBI_LIB is not None:
print(f"FOUND GUROBI library {GUROBI_LIB!r}: {lib_path}")
libraries.append(GUROBI_LIB)
compile_args.append("/DHAVE_GUROBI" if os.name == "nt" else "-DHAVE_GUROBI")
break
Expand Down

0 comments on commit 4fbea3c

Please sign in to comment.