Skip to main content

Cross-platform installer for the MATLAB runtime

Project description

Cross-platform installer for the MATLAB Runtime

This is a small package that simply allows to

TOC

Installation

pip install matlab-runtime

Command line tool

usage: install_matlab_runtime [-h] [-v VERSION ...] [-p PREFIX] [-u] [-y]

Install any matlab runtime in any location.

options:

  -h, --help        Show this help message and exit

  -v, --version     Version of the runtime to [un]install,
                    such as 'latest' or 'R2022b' or '9.13'.
                    Default is 'all' if '--uninstall' else 'latest'.

  -p, --prefix      Installation prefix. Default:
                    * Windows:  C:\Program Files\MATLAB\MATLAB Runtime\
                    * Linux:    /usr/local/MATLAB/MATLAB_Runtime
                    * MacOS:    /Applications/MATLAB/MATLAB_Runtime

  -u, --uninstall   Uninstall this version of the runtime.
                    Use '--version all' to uninstall all versions.

  -y, --yes         Default answer (usually yes) to all questions.
                    BY USING THIS OPTION, YOU ACCEPT THE TERMS OF THE MATLAB
                    RUNTIME LICENSE. THE MATLAB RUNTIME INSTALLER WILL BE RUN
                    WITH THE ARGUMENT `-agreeToLicense yes`.
                    IF YOU ARE NOT WILLING TO DO SO, DO NOT CALL THIS FUNCTION.
                    https://mathworks.com/help/compiler/install-the-matlab-runtime.html

  -x, --patch       Patch the runtime if needed.

Python API

Examples

Install a version of the runtime:

from matlab_runtime import install, guess_prefix

version = "R2024b"
install(version, auto_answer=True)

print(guess_prefix())

Import a compiled MATLAB package:

import my_matlab_project
from matlab_runtime import init, import_deployed

init("R2024b")  # Same version used when compiling the package

my_matlab_project = import_deployed(my_matlab_project)
my_matlab_project.my_function()

Note that my_matlab_project only needs to contain an (eventually empty) __init__.py and the compiled CTF file with the same name as the module. None of the other files spit out by the MATLAB compiler are requried.

└── my_matlab_project/
    ├── __init__.py
    └── my_matlab_project.ctf

API

def guess_prefix():
    """
    Guess the MATLAB Runtime installation prefix.

    If the environment variable `"MATLAB_RUNTIME_PATH"` is set, return it.

    Otherwise, the default prefix is platform-specific:

    * Windows:  C:\\Program Files\\MATLAB\\MATLAB Runtime\\
    * Linux:    /usr/local/MATLAB/MATLAB_Runtime
    * MacOS:    /Applications/MATLAB/MATLAB_Runtime

    Returns
    -------
    prefix : str
    """
    ...

def install(version=None, prefix=None, auto_answer=False):
    """
    Install the matlab runtime.

    !!! warning
        BY SETTING `default_answer=True`, YOU ACCEPT THE TERMS OF THE
        MATLAB RUNTIME LICENSE. THE MATLAB RUNTIME INSTALLER WILL BE
        RUN WITH THE ARGUMENT `-agreeToLicense yes`.
        IF YOU ARE NOT WILLING TO DO SO, DO NOT CALL THIS FUNCTION.

        https://mathworks.com/help/compiler/install-the-matlab-runtime.html

    Parameters
    ----------
    version : [list of] str, default="latest"
        MATLAB version, such as 'latest' or 'R2022b' or '9.13'.
    prefix : str, optional
        Install location. Default:
        * Windows:  C:\\Program Files\\MATLAB\\MATLAB Runtime\\
        * Linux:    /usr/local/MATLAB/MATLAB_Runtime
        * MacOS:    /Applications/MATLAB/MATLAB_Runtime
    default_answer : bool
        Default answer to all questions.
        **This entails accepting the MATLAB Runtime license agreement.**

    Raises
    ------
    UserInterruptionError
        If the user answers no to a question.
    """
    ...

def uninstall(version=None, prefix=None, auto_answer=False):
    """
    Uninstall the matlab runtime.

    Parameters
    ----------
    version : [list of] str, default="all"
        MATLAB version, such as 'latest' or 'R2022b' or '9.13'.
        If 'all', uninstall all installed versions.
    prefix : str, optional
        Install location. Default:
        * Windows:  C:\\Program Files\\MATLAB\\MATLAB Runtime\\
        * Linux:    /usr/local/MATLAB/MATLAB_Runtime
        * MacOS:    /Applications/MATLAB/MATLAB_Runtime
    auto_answer : bool
        Default answer to all questions.
    """
    ...

def init(
    version="latest_installed",
    install_if_missing=False,
    prefix=None,
    auto_answer=False,
):
    """
    Set current environment so that the MATLAB Python SDK is properly
    linked and usable.

    Parameters
    ----------
    version : str, default="latest_installed"
        MATLAB version, such as 'latest' or 'R2022b' or '9.13'.
        If 'latest_installed', use the most recent currently installed
        version. If no version is installed, equivalent to 'latest'.
    install_if_missing : bool
        If target version is missing, run installer.
    prefix : str, optional
        Install location. Default:
        * Windows:  C:\\Program Files\\MATLAB\\MATLAB Runtime\\
        * Linux:    /usr/local/MATLAB/MATLAB_Runtime
        * MacOS:    /Applications/MATLAB/MATLAB_Runtime
    default_answer : bool
        Default answer to all questions.
        **This entails accepting the MATLAB Runtime license agreement.**
    """
    ...

def import_deployed(*packages):
    """
    Initialize compiled MATLAB packages so that they can be used from python.

    Parameters
    ----------
    *packages : module | str
        Python package that contains a compiled MATLAB package (a ctf file).

    Returns
    -------
    *modules : module
        Imported MATLAB modules.
    """
    ...

Troubleshooting

MacOS

mpython / mwpython

The MATLAB SDK cannot be used with the normal python interpreter on MacOS. Instead, the MATLAB runtime ships with its own interpreter called mwpython.

However, mwpython does not interface correctly with conda environments (it overrides environement variables that cause compiled libraries to not be correctly loaded). For example, mwpython crashes when importing scipy.sparse.

Instead, we provide our own wrapper, mpython, which is automatically installed with this package. It does solve the conda environement issue.

That said, the matplotlib package still cannot be used with this wrapper (nor can it be used with MATLAB's mwpython).

Jupyter + libcrypto

When running jupyter, you may face an error related to libcrypto.3.dylib. If this happens, you may want to try running the runtime installation with the --patch option (or patch=True). Warning: this option modifies files whithin the MATLAB runtime installation folder, which may have unexpected effects. This is not a robust/thoroughly tested fix.

Jupyter + mpython

By default, jupyter runs its kernel through the "normal" python interpreter. In order to use the MATLAB packages in the kernel, it is necessary to inform jupyter that it should run its kernels through mpython.

To do so, locate the kernel file(s), usually at /Users/{username}/Library/Jupyter/kernels/{kernel_name}/kernel.json, and replace the path to the default interpreter (e.g., "/Users/{username}/miniforge3/envs/{env_name}/bin/python") with the path to mpython (e.g., "/Users/{username}/miniforge3/envs/{env_name}/bin/mpython").

If you cannot locate the kerenel file, install the kernel by running:

mpython -m ipykernel install --user --name {kernel_name}

You may need to install ipykernel beforehand.

Windows

DeclarativeService.dll not found

Python installation made from Microsoft Store on Windows will not work (raises DeclarativeService.dll not found), install it from Python website.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

matlab_runtime-0.0.6.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

matlab_runtime-0.0.6-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

Details for the file matlab_runtime-0.0.6.tar.gz.

File metadata

  • Download URL: matlab_runtime-0.0.6.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for matlab_runtime-0.0.6.tar.gz
Algorithm Hash digest
SHA256 ea1fec3c4eaa78115c3b57dc7a7114d12b581c8f9f165d608057e415b13baf0a
MD5 0c542442b9a53cd5042f1b07d8597222
BLAKE2b-256 0235bb9f7cb9b9ba7e1fccb1e1eb243f2b6372ddedd42b49e1d7a8d926bf4d5e

See more details on using hashes here.

Provenance

The following attestation bundles were made for matlab_runtime-0.0.6.tar.gz:

Publisher: publish_on_release.yml on balbasty/matlab-runtime

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file matlab_runtime-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: matlab_runtime-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 19.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for matlab_runtime-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 a0c44532b97f02d700185e9e619a710ddd16b988fab93961ba27f102e9c189e2
MD5 47ec5638804b56f79404e2cebacd2789
BLAKE2b-256 5d3861b659176c4841702c8530d237420808c598fab138fb6ba3e305d5d4b976

See more details on using hashes here.

Provenance

The following attestation bundles were made for matlab_runtime-0.0.6-py3-none-any.whl:

Publisher: publish_on_release.yml on balbasty/matlab-runtime

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page