diff --git a/CHANGELOG.md b/CHANGELOG.md index 719b103a1..da9fc99fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Added basic type stubs to help with IDE autocompletion and type checking. - MatrixVariable comparisons (<=, >=, ==) now support numpy's broadcast feature. - Added methods: getMaxDepth(), getPlungeDepth(), getLowerbound(), getCutoffbound(), getNNodeLPIterations(), getNStrongbranchLPIterations(). +- setup.py now automatically detects conda environments when SCIPOPTDIR is not defined. ### Fixed - Implemented all binary operations between MatrixExpr and GenExpr - Fixed the type of @ matrix operation result from MatrixVariable to MatrixExpr. diff --git a/INSTALL.md b/INSTALL.md index bdac22648..775556ef0 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -32,6 +32,8 @@ you need to specify the install location using the environment variable `set SCIPOPTDIR=` (**cmd**, **Cmder**, **WSL**)\ `$Env:SCIPOPTDIR = ""` (**powershell**) +**Note:** If `SCIPOPTDIR` is not set, the setup script will automatically attempt to detect a conda environment (via the `CONDA_PREFIX` environment variable) and use it if available. If no conda environment is detected, it will fall back to searching global installation paths. + `SCIPOPTDIR` needs to have a subdirectory `lib` that contains the library, e.g. `libscip.so` (for Linux) and a subdirectory `include` that contains the corresponding header files: diff --git a/setup.py b/setup.py index f1f5f48d2..07c1c53bb 100644 --- a/setup.py +++ b/setup.py @@ -7,16 +7,28 @@ extra_compile_args = [] extra_link_args = [] -# if SCIPOPTDIR is not set, we assume that SCIP is installed globally +# if SCIPOPTDIR is not set, try to detect conda environment, otherwise assume global installation if not scipoptdir: - if platform.system() == "Darwin": - includedir = "/usr/local/include" - libdir = "/usr/local/lib" + # check if we're in a conda environment + conda_prefix = os.environ.get("CONDA_PREFIX", "").strip('"') + + if conda_prefix and os.path.exists(os.path.join(conda_prefix, "include")): + includedir = os.path.join(conda_prefix, "include") + libdir = os.path.join(conda_prefix, "lib") + libname = "libscip" if platform.system() == "Windows" else "scip" + print(f"Detected conda environment at {conda_prefix}.") + print(f"Using include path {includedir}.") + print(f"Using library directory {libdir}.\n") else: - includedir = "." - libdir = "." - libname = "libscip" if platform.system() in ["Windows"] else "scip" - print("Assuming that SCIP is installed globally, because SCIPOPTDIR is undefined.\n") + # fall back to global installation + if platform.system() == "Darwin": + includedir = "/usr/local/include" + libdir = "/usr/local/lib" + else: + includedir = "." + libdir = "." + libname = "libscip" if platform.system() == "Windows" else "scip" + print("Assuming that SCIP is installed globally, because SCIPOPTDIR is undefined.\n") else: @@ -51,7 +63,7 @@ else: # assume that SCIP is installed on the system libdir = os.path.abspath(os.path.join(scipoptdir, "lib")) - libname = "libscip" if platform.system() in ["Windows"] else "scip" + libname = "libscip" if platform.system() == "Windows" else "scip" print(f"Using include path {includedir}.") print(f"Using SCIP library {libname} at {libdir}.\n")