Straight to the point. I have Matlab 2018b, installed on mac, running BigSur (macos 11.4), with the default shell set as ZSH. In addition to the default python versions on the OS (2.7 & 3.8.2), Matlab 2018b compatibility is limited to Python3.5/3.6. Attempting to install 3.6.13 and other versions directly couldn't be performed on the OS - there are plenty of refs to this. Note, any reference to PYENV here is using the terminal as my Matlab isn't recent enough to support pyenv.m - I have to use pyversion.
Eventually, I found pyenv worked with more hacking (eg gitmemory, accessed 2021-07-01), and I now have 3.6.13 installed in my local directory (/Users/Pete/.pyenv/versions/3.6.13/*). However, I cannot get Matlab to call any of the libraries (I think this is the correct term). I've gone through the various answers I can find and none of them work for me. As I've used PYENV to install python, it is now located in hidden directory on home path, so I've changed this by pyversion.
pyversion
version: '3.6'
executable: '/Users/pete/.pyenv/versions/3.6.13/bin/python3'
library: ''
home: '/Users/pete/.pyenv/versions/3.6.13'
isloaded: 0
Running py to force a python load (hopefully!) then
py
py.numpy
Undefined variable "py" or class "py.numpy".
Still not loaded.
getenv('PATH')
ans =
'/usr/bin:/bin:/usr/sbin:/sbin'
This last one looked suspicious as Python executable isn't located here - according to terminal, python works fine with the pyenv install, and I'm able to call the common "numpy" library with ease.
TERMINAL OUTPUT (NOT Matlab):
Last login: Thu Jul 1 11:07:29 on ttys000
pete@Petes-MacBook-Pro ~
Python 3.6.13 (default, Jun 29 2021, 13:19:52)
[GCC Apple LLVM 12.0.5 (clang-1205.0.22.11)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> import sys
>>> sys.path
['', '/Users/pete/.pyenv/versions/3.6.13/lib/python36.zip', '/Users/pete/.pyenv/versions/3.6.13/lib/python3.6', '/Users/pete/.pyenv/versions/3.6.13/lib/python3.6/lib-dynload', '/Users/pete/.local/lib/python3.6/site-packages', '/Users/pete/.pyenv/versions/3.6.13/lib/python3.6/site-packages']
>>> np.array(5)
array(5)
>>>
I've had a go at setting up the setenv('PATH'), but no luck with the python function being able to run...
setenv('PATH',fullfile('/Users/Pete/.pyenv/versions/3.6.13/lib'))
>> getenv('PATH')
ans =
'/Users/Pete/.pyenv/versions/3.6.13/lib'
>> py
>> py.numpy
Undefined variable "py" or class "py.numpy".
>> pyversion
version: '3.6'
executable: '/Users/pete/.pyenv/versions/3.6.13/bin/python3'
library: ''
home: '/Users/pete/.pyenv/versions/3.6.13'
isloaded: 0
>> setenv('PATH',fullfile('/Users/Pete/.pyenv/versions/3.6.13/bin/'))
>> py
>> pyversion
version: '3.6'
executable: '/Users/pete/.pyenv/versions/3.6.13/bin/python3'
library: ''
home: '/Users/pete/.pyenv/versions/3.6.13'
isloaded: 0
>> py.numpy
Undefined variable "py" or class "py.numpy".
No matter how I have called this, the logical
is always returned.
I'm obviously able to run Python via the terminal, but really wanted to have the option to run out of Matlab as this is what I'm more familiar with, and feel I can do more debugging this way, not to mention that ultimately, it should work once I get the setup right!
Any advice or things to try based on the above?
Thanks again in advance!