Python fails to load after installing via (zsh's) pyenv (Python, R2018b, macos)
古いコメントを表示
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 ~ % python3
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
isloaded: 0
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!
採用された回答
その他の回答 (5 件)
Yongjian Feng
2021 年 7 月 1 日
0 投票
Hello Pete,
Python path is different from the environment variable PATH. It is PYTHONPATH. Try to set PYTHONPATH instead.
Thanks,
Yongjian
11 件のコメント
Yongjian Feng
2021 年 7 月 1 日
PYTHONPATH is for python to look for packages (like numpy). PATH is for matlab to look for python executable.
So maybe PYTHONPATH should be the following instead? Do you have your numpy installed there?
'/Users/Pete/.pyenv/versions/3.6.13/lib'
Pete
2021 年 7 月 1 日
Yongjian Feng
2021 年 7 月 1 日
try
which py
Pete
2021 年 7 月 1 日
Pete
2021 年 7 月 1 日
Pete
2021 年 7 月 1 日
Yongjian Feng
2021 年 7 月 4 日
First make sure py is still good. Try
py.list
It should return an empty list
[]
Pete
2021 年 7 月 5 日
Pete
2021 年 7 月 5 日
Yongjian Feng
2021 年 7 月 5 日
Our document recommends to use pyenv, instead of pyversion, at least for the latest R2021a.
Please try pyenv(https://www.mathworks.com/help/matlab/ref/pyenv.html), even though you are using R2018
Pete
2021 年 7 月 5 日
1 件のコメント
Yongjian Feng
2021 年 7 月 5 日
We can try more things. On my macbookpro it loads 2.7 successfully once started. Yours doesn't load python at all. Please try this one from matlab command line first
pyversion 3.6
Pete
2021 年 7 月 5 日
1 件のコメント
Yongjian Feng
2021 年 7 月 5 日
I see. You are using python virtual env. The worse case scenario, we might need to install python not in the virtual env, if it is possible for you.
But before that, let see if we can get system working. Please try this:
setenv('PATH', ['/Users/pete/.pyenv/shims/', pathsep, getenv('PATH')]);
system('python3 --version')
カテゴリ
ヘルプ センター および File Exchange で MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!