This chapter describes how to verify that the MOSEK Python API has been installed and works, and how to run the distributed examples.
The MOSEK Python interface, PyMosek, requires a MOSEK installation and a full Python 2.5 or 2.6 installation with ctypes support. Furthermore, MOSEK can use arrays from the NumPy package from scipy.org.
A Python installer can be obtained from the official site:
The NumPy package providing arrays and mathematical functionality can be obtained from:
Please note that starting from MOSEK version 6.0 PyMosek uses the NumPy package rather than the Numeric package. If the NumPy package is not present, the PyMosek package includes a minimal array implementation, mosek.array, that can be used instead.
To use the PyMosek interface you will need a working installation of MOSEK and Python. See the MOSEK Installation Manual for instructions on installing and testing MOSEK.
MOSEK includes a binary Python that can be used interactively or for running scripts, but if you have a Python installed on your system you may use that instead.
The PyMosek module is located in on of the directories
mosek\6\tools\platform\win64x86\python\2 mosek\6\tools\platform\win32x86\python\2
Examples using the PyMosek interface are found in
mosek\6\tools\examples\python
To run one of the distributed examples, open a DOS box and type
C: cd "\Program Files\mosek\6\tools\examples\python"
then to execute example lo1 type
python lo1.py
MOSEK can be installed by unpacked it to some directory — the complete procedure is described in the MOSEK Installation Manual. In the following we assume that assume that MOSEK was unpacked to the user's home directory, and that all steps in the installation was completed.
The PyMosekmodule is located in
mosek/6/tools/platform/$PLATFORM/python/2
where $PLATFORM is linux32x86 or linux64x86, depending on the platform.
The Python examples are found in
mosek/6/tools/examples/python
Before the PyMosek API can be used, the system environment must be set correctly up:
You can verify that this is the case as follows: Open a shell and type
echo $PATH
This prints a “:”-separated list of paths which should contain the path to MOSEK. Then type
echo $PYTHONPATH
This prints a “:”-separated list of paths which should contain the path to the PyMosek module. If one of the above were missing, they must be set up. This can be done either temporarily or permanently:
The variables can be temporarily set in current shell. In Bash this can be done by typing
export LD_LIBRARY_PATH="$HOME/mosek/6/tools/platform/$PLATFORM/bin:$LD_LIBRARY_PATH" export PYTHONPATH="$HOME/mosek/6/tools/platform/$PLATFORM/python/2:$PYTHONPATH"
Note that other shells may require a different syntax.
The variables can be permanently set by including following lines in /.bashrc
if [ -z "$LD_LIBRARY_PATH" ]; then export LD_LIBRARY_PATH="$HOME/mosek/6/tools/platform/$PLATFORM/bin" else export LD_LIBRARY_PATH="$HOME/mosek/6/tools/platform/$PLATFORM/bin:$LD_LIBRARY_PATH" fi if [ -z "$PYTHONPATH" ]; then export PYTHONPATH="$HOME/mosek/6/tools/platform/$PLATFORM/python/2" else export PYTHONPATH="$HOME/mosek/6/tools/platform/$PLATFORM/python/2:$PYTHONPATH" fi
Please note that other shells may use a different syntax.
To run a Python script, open a shell, change directory to where the script is located, and type
python myscript.py
where myscript.py is the name of the Python script.
The PyMosek module is implemented as a pure Python module using ctypes to call native DLLs. The minimal array module mosek.array is implemented as a pure binary DLL plus a pure Python ctypes-based module.
This means that the PyMosek module is compatible with Python 2.5 and all later 2.X versions. The new Python 3.X series introduces several language incompatibilities, which means that the module is not immediately compatible with Python 3.X; a Python 3.X compatible version is being developed, but is not be included in the distribution — please contact support@mosek.com if you wish to use Python 3 with MOSEK.