Unable to run basic python commands despite building python with --enabled-shared on macOS Monterey

I've been building python locally to run with matlab. I have successfully built python in version 3.8.12, and 3.10.0 with the enabled-shared flag and created a virtual python enviroment using the venv package with the enviroment being called 'python-env'. I have sucessfully pointed to the right executable in matlab using the pyenv command and get the output shown below. But calling simple commands like py.open, or py.print("Hello") fail with the error line "Unable to resolve the name 'py.print'."
ans =
PythonEnvironment with properties:
Version: "3.8"
Executable: "/Users/adammurdock/Programming_Stuff/Reverb Project/python-env/bin/python"
Library: "/Users/adammurdock/.pyenv/versions/3.8.12/lib/libpython3.8.dylib"
Home: "/Users/adammurdock/Programming_Stuff/Reverb Project/python-env"
Status: NotLoaded
ExecutionMode: OutOfProcess

Answers (1)

Hello Adam,
If you encounter the error message 'Unable to resolve the name py.myFuncName' in MATLAB, it may be caused by installation issues related to Python. One possible reason for this error is a compatibility issue between Python and MATLAB. Specifically, only Python 3.10 is compatible with MATLAB R2023a and R2022b.
To resolve this issue, I recommend that you review the following MATLAB documentation. This should provide you with the necessary information to troubleshoot and fix the error.
  1. Configure Your System to Use Python
  2. Unable to resolve the name py.myfunc
  3. Versions of Python Compatible with MATLAB Products by Release
  4. Python virtual environments with MATLAB
Hope this helps!
Thank you.

Products

Release

R2023a

Tags

Asked:

on 1 Jun 2023

Edited:

on 5 Jun 2023

Community Treasure Hunt

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

Start Hunting!