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 requires a MOSEK installation, a full Python installation and the Numerical Python extension. A Python installer can be obtained from the official site
or packaged from
The Numeric extension providing arrays and mathematical functionality can be obtained from
This package is not required, but the MOSEK Python API can use Numeric arrays more efficiently than generic arrays or lists. The Numerical package is expected to be replaced by NumPy in the near future.
To use the MOSEK Python interface, a working MOSEK installation must be present — see the MOSEK Installation manual for instructions. In the following we assume that assume that MOSEK is installed in the default directory
C:\Program Files\mosek
Please note that this may be different for other language settings than US English. The MOSEK Python interface is defined in
C:\Program Files\mosek\5\tools\platform\win\bin\pymosek.pyd
or
C:\Program Files\mosek\5\tools\platform\win64\bin\pymosek.pyd
depending on the platform.
The distributed Python examples are found in
C:\Program Files\mosek\5\tools\examples\python
To run one of the distributed examples, open a DOS box and type
C: cd "\Program Files\mosek\5\tools\examples\python"
then to execute example lo1 type
python lo1.py
MOSEK can be installed by unzipping it to some directory — the complete procedure is described in the MOSEK Installation manual for instructions. In the following we assume that assume that MOSEK was unzipped to the user's home directory, and that all steps in the installation was completed.
The MOSEK Python API is defined in the library
pymosek.so
in one of the directories
~/mosek/5/tools/platform/linux32x86/bin/pymosek.so ~/mosek/5/tools/platform/linux64x86/bin/pymosek.so
depending on the platform. All other required libraries reside in the same directory as this module.
The distributed Python examples are found in
C:/mosek/5/tools/examples/python
Before the MOSEK Python 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 pymosek.so. 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=$LD_LIBRARY_PATH:"$HOME/mosek/5/tools/platform/<arch>/bin" export PYTHONPATH=$PYTHONPATH:"$HOME/mosek/5/tools/platform/<arch>/bin"
where <arch> is either “linux32x86” (on 32-bit Linux) or “linux64x86” (on 64-bit linux). 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/5/tools/platform/<arch>/bin" else export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"$HOME/mosek/5/tools/platform/<arch>/bin" fi if [ -z "$PYTHONPATH" ]; then export PYTHONPATH="$HOME/mosek/5/tools/platform/<arch>/bin" else export PYTHONPATH=$PYTHONPATH:"$HOME/mosek/5/tools/platform/<arch>/bin" fi
where <arch> is either “linux32x86” (on 32-bit systems), “linux64x86” (on AMD64 or EM64T) or “linuxia64” (on Itanium). Note that other shells may require 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.