MATLAB® based Python® Requirements manager

MPyReq is a MATLAB-based Python requirements manager that simplifies installing and configuring Python environments for MATLAB projects.
74 download
Aggiornato 17 dic 2025

Visualizza la licenza

MPyReq is a MATLAB-based Python requirements manager that simplifies installing and configuring Python environments for MATLAB projects. It handles Python version management, package installations, git repository cloning, and weight file downloads with a simple API. MPyReq ensures consistent Python environments across sessions by caching configurations and providing runtime setup for your Python dependencies.
Setup
Call MPyReq.setInstallFolder(largeSSDFolder) to set the install folder.
This only needs to be done once per machine. All subsequent uses of MPyReq share downloaded content from this folder.
Getting Started
Invoke help to see documentation
help MPyReq.m
Note: Click 'Open in MATLAB Online' and run the demoCellpose example in MATLAB Online. Remember to follow step 2 & 3 above. You can set install folder to "/tmp/pydata" when trying it out.
Example
% Do this once per machine (saved in settings)
MPyReq.setInstallFolder("pathToLocalLargeSSDFolder")
% First ever run of this section - Does installation and Runtime setup
% First run in a subsequent session - Just Runtime Setup
% Second run in any session - A very quick check to ensure env is up
MPyReq.python("3.12");
MPyReq.pipPackage("cellpose");
im = imread("AT3_1m4_01.tif");
% Use Python interface to call into Python code
% See: https://cellpose.readthedocs.io/en/latest/api.html
model = py.cellpose.models.CellposeModel(gpu=true);
outputs = model.eval(im);
labels = uint16(outputs{1});
imageshow(im,OverlayData=labels)
More Examples
Run the following examples after ensuring to set an installation folder using the call below. Ideally, this folder should be a fast access (e.g SSD) with ~15+ GB free space. These examples download large libraries and model files. These examples were tested on a glnxa64 machine with a working GPU.
Ensure to run this to clear the python environment between two demo runs:
terminate(pyenv); clear MPyReq
demoCellpose - Run https://www.cellpose.org/ cell segmentation model.
demoStarDist - Run https://github.com/stardist/stardist object detection with star convex shapes
demoDepthPro - Run https://github.com/apple/ml-depth-pro A quick, sharp monocular metric depth model.
demoSAM2 - Run https://github.com/facebookresearch/sam2 Segment Anything Model 2
demoVGGT - Run https://vgg-t.github.io/ Visual Geometry Grounded Transformer
Troubleshooting
Python Errors or Package Conflicts
MPyReq does not resolve package conflicts. If you tried to install Package A first which used x.xx version of an upstream package U, and then tried to add Package B which used y.yy version of U in the same pyenv session - you will get odd Python errors due to conflicts in required version of Package U. Best strategy is to only work with one 'project' at a time - as shown in the examples. And use the following between switching projects:
terminate(pyenv); clear MPyReq
MPyReq automatcially does this only when the required Python version changes.
If you have a workflow needing to combine two models which have conflicting requirements, you will have to run the above between calls to these models. For best performance (and when possible), you should run all data through model 1 first, serialize the results into disk, and then run model 2 on the saved data.
win64
MPyReq is expected to work on win64. However, installing CUDA enabled PyTorch has not been tested. MPyReq uses uv as the install engine, so uv environment variables are honored. You can experiment with setting this environment variable before invoking any installs to guide uv to download from the pytorch index
setenv("UV_EXTRA_INDEX_URL","https://download.pytorch.org/whl/cu126")

Cita come

Ashish Uthama (2025). MATLAB® based Python® Requirements manager (https://it.mathworks.com/matlabcentral/fileexchange/182230-matlab-based-python-requirements-manager), MATLAB Central File Exchange. Recuperato .

Compatibilità della release di MATLAB
Creato con R2025b
Compatibile con R2019b e release successive
Compatibilità della piattaforma
Windows macOS Linux
Tag Aggiungi tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Versione Pubblicato Note della release
1.0.19

Add addToPythonPath(folder) API

1.0.18

Removed path troubleshooting section (fixed in code)

1.0.17

Auto addpath

1.0.16

Add GPU support for starDist

1.0.15

Description updates

1.0.14

win64 bug fix

1.0.13

Add startdist example

1.0.12

Note on MO

1.0.11

Note on example platform tested

1.0.10

Troubleshooting section

1.0.9

Fix default verbose to false

1.0.8

Push verbose flag all the way down

1.0.7

Updated description with an example

1.0.6

Help update

1.0.5

Fix links

1.0.4

Typo in error

1.0.3

Update setup instructions

1.0.2

re-include examples

1.0.1

Dont default installation path since it can fill up with large data. Always explicitly ask user.

1.0.0