Using mwpython with conda environment (MacOS, M1)

Running a python script which uses the MatLab runtime, I encounter:
RuntimeError: On the Mac, you must run mwpython rather than python to start a session or script that imports your package. For more details, execute "mwpython -help" or see the package documentation.
MatLab runtime version 2022b. Using a conda environment as python (3.10). MacOS 12.6, M1 processor.
I am trying to run mwpython using a conda environment. With my conda environment active and executing python, trying something like this:
>>> import os
>>> import subprocess
>>> os.environ["VIRTUAL_ENV"] = "/Users/.../opt/anaconda3/envs/my_env"
>>> subprocess.call( "/Applications/MATLAB/MATLAB_Runtime/R2022b/bin/mwpython", shell=True )
However, the python prompt does not return. Instead, I get:
dyld[10217]: missing symbol called
/Applications/MATLAB/MATLAB_Runtime/R2022b/bin/mwpython: line 254: 10217 Abort trap: 6 "/Applications/MATLAB/MATLAB_Runtime/R2022b/bin/maci64/mwpython3.10.app/Contents/MacOS/mwpython3.10"
134
Would like some clarity regarding how to run mwpython using a conda environment with this bash script and where (or how) to activate/run mwpython in my script.
Thanks,

2 Comments

Looks like this question is tangentially related to this post here:
If I understand this correctly, activating my python 3.10 conda environment and running the bash script should work. But instead, I get this message:
dyld[11406]: Library not loaded: '@rpath/libpython3.10.dylib'
...
Abort trap: 6 "/Applications/MATLAB/MATLAB_Runtime/R2022b/bin/maci64/mwpython3.10.app/Contents/MacOS/mwpython3.10"
Which suggests that I shouldn't need to do anything else to point to my conda environment. However, mwpython simply can't find the corresponding dylib.
Copying
/Users/.../opt/anaconda3/envs/my_env/lib/libpython3.10.dylib
into folder
/Applications/MATLAB/MATLAB_Runtime/R2022b/runtime/maci64
Allows the bash script to find the correct python, e.g., the following runs without errors:
bash mwpython my_script.py
But I don't know why this is broken. Also, of course, my_script.py won't be able to find libraries installed into your conda environment. As a work-around, add the folder with the library binaries to your path:
import sys
sys.path.append( r'/Users/.../opt/anaconda3/envs/my_env/lib/python3.10/site-packages' )

Sign in to comment.

Answers (0)

Products

Release

R2022b

Asked:

on 14 Dec 2022

Edited:

on 16 Dec 2022

Community Treasure Hunt

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

Start Hunting!