Python – MATLAB not working: MATLAB cant find python environment, numpy not working, fooof not working
Hi everyone,
I’ve been stuck on trying to run some matlab-python code for a week now and nothing seems to work. I am trying to run the following code: https://github.com/fooof-tools/fooof_mat?tab=readme-ov-file which requires python to be compatible with MATLAB. I’ve read so many things but nothing has worked so far. This is my first time trying to code in python-matlab simultaneously so the answer might be something simple that I am just not aware of.
What has worked so far:
I created a new environment called ‘env’ which is located in location ‘fri_test’. In this environment I have installed fooof, matlibplot, pandas.
Then, I open a fresh MATLAB window and type in the following:
pyenv
This is the output:
ans =
PythonEnvironment with properties:
Version: "3.9"
Executable: "/Users/c1034944/fri_test/env/bin/python"
Library: "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/libpython3.9.dylib"
Home: "/Users/c1034944/fri_test/env"
Status: NotLoaded
ExecutionMode: InProcess
I then run:
python_env_path = ‘/Users/c1034944/fri_test/env/bin/python’
pyenv("Version",python_env_path);
py.list({‘This’,’is a’,’list’})
output:
ans =
Python list with no properties.
[‘This’, ‘is a’, ‘list’]
Lastly, run this again to check the python environment:
pyenv
output:
ans =
PythonEnvironment with properties:
Version: "3.9"
Executable: "/Users/c1034944/fri_test/env/bin/python"
Library: "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/libpython3.9.dylib"
Home: "/Users/c1034944/fri_test/env"
Status: Loaded
ExecutionMode: InProcess
ProcessID: "42704"
ProcessName: "MATLAB"
As you can see the ‘executable’ is finding the correct location of the environment I created in fri_test. The ‘ExecutionMode’ has also now updated to ‘InProcess’. However, the ‘Library" is still calling the python version from the Library/Developer.
To test if numpy is working, I run the following:
freq=([0 0.9766 1.9531 2.9297])
py.numpy.array(freq)
this is the error message:
Unable to resolve the name py.numpy.array.
More info: The ‘fooof’ code I am trying to run contains the following line: py.numpy.array(freqs), where ‘freqs’ is a list of 1 x 257 numbers. To my understanding py.numpy.array(freqs) converts the matlab (.mat) file ‘freqs’ into a python-compatible array.
Conclusion: I have no idea what is the issue here and why numpy is not working. I know that MATLAB and python versions are compatible, but maybe I am making a different mistake. I am hoping that finding a solution to numpy problem and that may fix the whole issue – is there any other way to convert .mat files into python arrays?
Any suggestions would be helpful!
Healthy Regards,
VyteHi everyone,
I’ve been stuck on trying to run some matlab-python code for a week now and nothing seems to work. I am trying to run the following code: https://github.com/fooof-tools/fooof_mat?tab=readme-ov-file which requires python to be compatible with MATLAB. I’ve read so many things but nothing has worked so far. This is my first time trying to code in python-matlab simultaneously so the answer might be something simple that I am just not aware of.
What has worked so far:
I created a new environment called ‘env’ which is located in location ‘fri_test’. In this environment I have installed fooof, matlibplot, pandas.
Then, I open a fresh MATLAB window and type in the following:
pyenv
This is the output:
ans =
PythonEnvironment with properties:
Version: "3.9"
Executable: "/Users/c1034944/fri_test/env/bin/python"
Library: "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/libpython3.9.dylib"
Home: "/Users/c1034944/fri_test/env"
Status: NotLoaded
ExecutionMode: InProcess
I then run:
python_env_path = ‘/Users/c1034944/fri_test/env/bin/python’
pyenv("Version",python_env_path);
py.list({‘This’,’is a’,’list’})
output:
ans =
Python list with no properties.
[‘This’, ‘is a’, ‘list’]
Lastly, run this again to check the python environment:
pyenv
output:
ans =
PythonEnvironment with properties:
Version: "3.9"
Executable: "/Users/c1034944/fri_test/env/bin/python"
Library: "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/libpython3.9.dylib"
Home: "/Users/c1034944/fri_test/env"
Status: Loaded
ExecutionMode: InProcess
ProcessID: "42704"
ProcessName: "MATLAB"
As you can see the ‘executable’ is finding the correct location of the environment I created in fri_test. The ‘ExecutionMode’ has also now updated to ‘InProcess’. However, the ‘Library" is still calling the python version from the Library/Developer.
To test if numpy is working, I run the following:
freq=([0 0.9766 1.9531 2.9297])
py.numpy.array(freq)
this is the error message:
Unable to resolve the name py.numpy.array.
More info: The ‘fooof’ code I am trying to run contains the following line: py.numpy.array(freqs), where ‘freqs’ is a list of 1 x 257 numbers. To my understanding py.numpy.array(freqs) converts the matlab (.mat) file ‘freqs’ into a python-compatible array.
Conclusion: I have no idea what is the issue here and why numpy is not working. I know that MATLAB and python versions are compatible, but maybe I am making a different mistake. I am hoping that finding a solution to numpy problem and that may fix the whole issue – is there any other way to convert .mat files into python arrays?
Any suggestions would be helpful!
Healthy Regards,
Vyte Hi everyone,
I’ve been stuck on trying to run some matlab-python code for a week now and nothing seems to work. I am trying to run the following code: https://github.com/fooof-tools/fooof_mat?tab=readme-ov-file which requires python to be compatible with MATLAB. I’ve read so many things but nothing has worked so far. This is my first time trying to code in python-matlab simultaneously so the answer might be something simple that I am just not aware of.
What has worked so far:
I created a new environment called ‘env’ which is located in location ‘fri_test’. In this environment I have installed fooof, matlibplot, pandas.
Then, I open a fresh MATLAB window and type in the following:
pyenv
This is the output:
ans =
PythonEnvironment with properties:
Version: "3.9"
Executable: "/Users/c1034944/fri_test/env/bin/python"
Library: "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/libpython3.9.dylib"
Home: "/Users/c1034944/fri_test/env"
Status: NotLoaded
ExecutionMode: InProcess
I then run:
python_env_path = ‘/Users/c1034944/fri_test/env/bin/python’
pyenv("Version",python_env_path);
py.list({‘This’,’is a’,’list’})
output:
ans =
Python list with no properties.
[‘This’, ‘is a’, ‘list’]
Lastly, run this again to check the python environment:
pyenv
output:
ans =
PythonEnvironment with properties:
Version: "3.9"
Executable: "/Users/c1034944/fri_test/env/bin/python"
Library: "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/libpython3.9.dylib"
Home: "/Users/c1034944/fri_test/env"
Status: Loaded
ExecutionMode: InProcess
ProcessID: "42704"
ProcessName: "MATLAB"
As you can see the ‘executable’ is finding the correct location of the environment I created in fri_test. The ‘ExecutionMode’ has also now updated to ‘InProcess’. However, the ‘Library" is still calling the python version from the Library/Developer.
To test if numpy is working, I run the following:
freq=([0 0.9766 1.9531 2.9297])
py.numpy.array(freq)
this is the error message:
Unable to resolve the name py.numpy.array.
More info: The ‘fooof’ code I am trying to run contains the following line: py.numpy.array(freqs), where ‘freqs’ is a list of 1 x 257 numbers. To my understanding py.numpy.array(freqs) converts the matlab (.mat) file ‘freqs’ into a python-compatible array.
Conclusion: I have no idea what is the issue here and why numpy is not working. I know that MATLAB and python versions are compatible, but maybe I am making a different mistake. I am hoping that finding a solution to numpy problem and that may fix the whole issue – is there any other way to convert .mat files into python arrays?
Any suggestions would be helpful!
Healthy Regards,
Vyte fooof, python, matlab, matlab python, numpy, python array, library, executable MATLAB Answers — New Questions