RuntimeError: Mosek library is not loaded #11
-
While try using File "/Users/energy/Downloads/PREP-SHOT/prepshot/model.py", line 11, in main
model = mosek.Model()
File "/Users/energy/miniconda3/envs/prep-shot/lib/python3.9/site-packages/pyoptinterface/_src/mosek.py", line 352, in __init__
init_default_env()
File "/Users/energy/miniconda3/envs/prep-shot/lib/python3.9/site-packages/pyoptinterface/_src/mosek.py", line 105, in init_default_env
DEFAULT_ENV = Env()
RuntimeError: Mosek library is not loaded. Code example: from pyoptinterface import mosek
model = mosek.Model() I have installed export MOSEK_10_2_BINDIR=/Users/energy/mosek/10.2/tools/platform/osxaarch64/bin/
export PATH=$PATH:/Users/energy/mosek/10.2/tools/platform/osxaarch64/bin/ While directly typing MOSEK Version 10.2.1 (Build date: 2024-6-13 08:48:49)
Copyright (c) MOSEK ApS, Denmark WWW: mosek.com
Platform: MACOSX/aarch64
*** No input file specfied. No optimization is performed.
Return code - 0 [MSK_RES_OK] By the way, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Are you using the latest 0.2.4 version of PyOptInterface? Autoloading Mosek 10.2 is only added in 0.2.4. Can you run You can run the script as follows to test why it cannot load the library: import os
import platform
from pathlib import Path
import re
import logging
logging.basicConfig(level=logging.INFO)
from pyoptinterface import mosek
def detected_libraries():
libs = []
libname_pattern = {
"Linux": r"libmosek64\.so",
"Darwin": r"libmosek64\.dylib",
"Windows": r"mosek64_(\d+)_(\d+)\.dll",
}[platform.system()]
suffix_pattern = {
"Linux": "*.so",
"Darwin": "*.dylib",
"Windows": "*.dll",
}[platform.system()]
# Environment
home = os.environ.get("MOSEK_10_2_BINDIR", None)
if home is None:
home = os.environ.get("MOSEK_10_1_BINDIR", None)
if home and os.path.exists(home):
dir = Path(home)
for path in dir.glob(suffix_pattern):
match = re.match(libname_pattern, path.name)
if match:
libs.append(str(path))
# mosekpy installation
try:
import mosek
dir = Path(mosek.__path__[0])
libname_pattern = {
"Linux": r"libmosek64\.so\.*",
"Darwin": r"libmosek64\.*\.dylib",
"Windows": r"mosek64_(\d+)_(\d+)\.dll",
}[platform.system()]
suffix_pattern = {
"Linux": "*.so.*",
"Darwin": "*.dylib",
"Windows": "*.dll",
}[platform.system()]
for path in dir.glob(suffix_pattern):
match = re.match(libname_pattern, path.name)
if match:
libs.append(str(path))
except Exception:
pass
# default names
default_libname = {
"Linux": "libmosek64.so",
"Darwin": "libmosek64.dylib",
"Windows": "mosek64_10_2.dll",
}[platform.system()]
libs.append(default_libname)
return libs
def autoload_library():
libs = detected_libraries()
for lib in libs:
ret = mosek.load_library(lib)
if ret:
logging.info(f"Loaded Mosek library: {lib}")
return True
else:
logging.info(f"Cannot load Mosek library from {lib}")
return False
autoload_library() |
Beta Was this translation helpful? Give feedback.
-
Thank you for your quick response! Previously I am using PyOptInterface 0.2.3 version. After I update to 0.2.4 version, error did not appear. Now By the way, while i can run the above script, i got following output: INFO:root:Loaded Mosek library: /Users/energy/mosek/10.2/tools/platform/osxaarch64/bin/libmosek64.dylib
INFO:root:Loaded Mosek library: /Users/energy/mosek/10.2/tools/platform/osxaarch64/bin/libmosek64.dylib I think my problem is solved, thank you very much! |
Beta Was this translation helpful? Give feedback.
Are you using the latest 0.2.4 version of PyOptInterface? Autoloading Mosek 10.2 is only added in 0.2.4.
Can you run
ls /Users/energy/mosek/10.2/tools/platform/osxaarch64/bin/
to show its content?You can run the script as follows to test why it cannot load the library: