Install & Compatibility
Where this runs
tested against v11.2.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
build_error
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 4.9s · import 0.030s · 134MB
137MB installed
● package 137MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
mosek
✓ import mosek
For the Optimizer API, or to access general MOSEK constants and environment.
fusion
✓ import mosek.fusion as msk
For the object-oriented Fusion API. The 'pythonic' submodule provides convenience operators.
This quickstart demonstrates a basic Linear Programming (LP) problem using MOSEK's Optimizer API. It initializes a MOSEK environment and task, defines variables and constraints, sets the objective, solves the problem, and retrieves the solution. A MOSEK license is required to run this code; ensure your license file is correctly configured, typically via the `MOSEKLM_LICENSE_FILE` environment variable or by placing `mosek.lic` in `~/.mosek/` (or `%USERPROFILE%\mosek\` on Windows).
import mosek
import os
# Configure MOSEK license path. Replace 'path/to/your/mosek.lic' with actual path.
# For academic/trial licenses, it often defaults to ~/.mosek/mosek.lic
# It's recommended to set MOSEKLM_LICENSE_FILE environment variable for production.
# For quickstart, ensure the license file is accessible or MOSEKLM_LICENSE_FILE is set.
# os.environ['MOSEKLM_LICENSE_FILE'] = os.environ.get('MOSEKLM_LICENSE_FILE', 'path/to/your/mosek.lic')
# Define a stream printer to capture MOSEK output (optional)
def streamprinter(text):
# print(text.strip())
pass
try:
# Create a MOSEK environment
with mosek.Env() as env:
# Attach a stream printer to the environment
env.set_Stream(mosek.streamtype.log, streamprinter)
# Create a task for optimization
with env.Task() as task:
task.set_Stream(mosek.streamtype.log, streamprinter)
# Problem: Minimize x + y subject to x >= 0, y >= 0, x + y >= 1
# Append two variables
task.appendvars(2)
# Set variable bounds to be free initially
task.putvarboundlist([0, 1], [mosek.boundkey.fr, mosek.boundkey.fr], [0.0, 0.0], [0.0, 0.0])
# Append one constraint
task.appendcons(1)
# Set constraint bound (x + y >= 1)
task.putconbound(0, mosek.boundkey.lo, 1.0, 1.0)
# Set coefficients for constraint (x + y)
task.putaij(0, 0, 1.0) # Constraint 0, Variable 0, Coefficient 1.0
task.putaij(0, 1, 1.0) # Constraint 0, Variable 1, Coefficient 1.0
# Set objective coefficients (Minimize x + y)
task.putclist([0, 1], [1.0, 1.0])
# Set objective sense to minimize
task.putobjsense(mosek.objsense.minimize)
# Solve the problem
task.optimize()
task.solutionsummary(mosek.streamtype.log)
# Get and print the solution
prosta = task.getprosta(mosek.soltype.itr)
if prosta == mosek.prosta.prim_feas_obj_and_dual_feas_obj:
xx = [0.0] * 2
task.getxx(mosek.soltype.itr, xx)
print(f"Solution: x = {xx[0]}, y = {xx[1]}")
else:
print("Problem status: ", prosta)
except mosek.Error as e:
print(f"MOSEK Error: {e.code} {e.msg}")
except Exception as e:
print(f"General Error: {e}")
Debug
Known issues
breakingMOSEK is commercial software and requires a valid license to function. Even after `pip install mosek`, you must obtain and configure a license file (e.g., `mosek.lic`) by placing it in a default location or setting the `MOSEKLM_LICENSE_FILE` environment variable. Without a license, optimization calls will fail.fixObtain a trial, academic, or commercial license from mosek.com and follow the licensing guide to place the `mosek.lic` file or set the `MOSEKLM_LICENSE_FILE` environment variable.
affects: All versions
breakingUpgrading to a new major version (e.g., from MOSEK 10 to 11) can introduce API incompatibilities and changes in default parameter behaviors. Users who have tuned solver parameters are recommended to re-evaluate their settings.fixConsult the release notes and interface changes section in the documentation for the specific major version upgrade. Re-evaluate any custom solver parameter settings.
affects: Across major versions (e.g., 10.x to 11.x)
deprecatedIn the Optimizer API, conic constraints restricted to `x ∈ K` for a variable `x` are deprecated and will be removed in a future major version.fixMigrate to using affine conic constraints instead.
affects: MOSEK 11.1.x and later
deprecatedThe MOSEK conda package is deprecated and may be dropped in a future release.fixPrefer `pip install mosek` for Python API installation.
affects: MOSEK 11.1.x and later
gotchaRepeatedly creating and destroying `mosek.Env()` or `mosek.fusion.Model` objects for many small optimization problems can incur significant performance overhead due to the license checkout system.fixReuse the MOSEK environment (or `mosek.fusion.Model` object) for multiple optimizations where possible, as the license token remains checked out within the environment's lifetime. Set `cacheLicense` to 'off' or `Model.putlicensewait` if specific license management is needed.
affects: All versions
gotchaUsing the Fusion API, assigning names to all variables, constraints, and other model elements can substantially increase problem setup time. This overhead should be avoided in time-critical applications.fixAvoid assigning names to model elements if setup time is critical for performance. Names are primarily for debugging and readability.
affects: All versions using Fusion API
gotchaPassing NumPy arrays of incorrect integer types (e.g., `int64` where `int32` is expected, or vice versa) to the MOSEK API will trigger warnings and cause the module to make internal copies, potentially impacting performance.fixEnsure that NumPy arrays passed to the MOSEK API have the expected integer data types (typically `int32` for indices, `float64` for numerical data) to avoid unnecessary internal data conversions.
affects: All versions
Errors
Common errors & fixes
mosek.Error: rescode.err_missing_license_file(1008): License cannot be located.
MOSEK requires a valid license file (`mosek.lic`) to operate, but the library cannot find it in its default search paths or the path specified by the `MOSEKLM_LICENSE_FILE` environment variable is incorrect or the license file itself is invalid.
fixEnsure your `mosek.lic` file is placed in a default location like `~/mosek/` (Linux/macOS) or `C:\Users\YOUR_USERNAME\mosek\` (Windows). Alternatively, set the `MOSEKLM_LICENSE_FILE` environment variable to the absolute path of your license file before importing MOSEK.
AttributeError: module 'mosek' has no attribute 'Env'
This error typically occurs when there is an import conflict, such as a user-created `mosek.py` file or an older/incorrect MOSEK installation shadowing the actual MOSEK package in Python's import path. This leads to the interpreter loading the wrong module.
fixCheck your Python environment for any files named `mosek.py` or directories named `mosek` that are not part of the official MOSEK installation. Remove or rename conflicting files/directories, or ensure the correct MOSEK installation path has precedence in your `PYTHONPATH`. Using a clean virtual environment and reinstalling MOSEK there can also resolve this.
ImportError: DLL load failed while importing _msk: The specified module could not be found.
On Windows, this error indicates that the operating system cannot locate the necessary MOSEK shared libraries (DLLs), usually because the MOSEK binary directory is not included in the system's `PATH` environment variable. Similar issues can occur on Linux/macOS if `LD_LIBRARY_PATH`/`DYLD_LIBRARY_PATH` are not correctly set.
fixAdd the MOSEK binary directory to your system's `PATH` environment variable. For example, on Windows, this might be `C:\Program Files\Mosek\11.1\tools\platform\win64x86\bin`. On Linux/macOS, it would be `<MOSEK_INSTALL_DIR>/mosek/11.1/tools/platform/<OS_ARCH>/bin` and might require setting `LD_LIBRARY_PATH` or `DYLD_LIBRARY_PATH`.
AttributeError: 'Task' object has no attribute '_Task__obj'
This error in the Optimizer API indicates that a MOSEK `Task` object has been prematurely garbage collected or deleted. This often happens when the object is accessed outside the `with` statement's scope where it was created, or after its explicit `delete()` method has been called.
fixEnsure that the `Task` object is kept within its proper scope, ideally by using it within a `with` statement, which guarantees proper resource management. For example: `with mosek.Task() as task: # use task here`.
Upgrade
Version history
11.2.2latest on PyPI · released Jun 10, 2026
Audit
Dependencies
PythonrequiredRequired Python version for compatibility.
NumPyoptionalRecommended for efficient data handling, especially with the Fusion API.
MOSEK Optimization Suite (native solver)requiredThe Python 'mosek' package is an interface to the underlying MOSEK solver, which needs to be installed and licensed separately. The pip package only contains the Python bindings.