Python - MATLAB not working: MATLAB cant find python environment, numpy not working, fooof not working
13 件のコメント
回答 (1 件)
Hi @Vyte Jan,
After going through your comments and reviewing the documentations provided at the links below,
https://www.mathworks.com/help/matlab/matlab_external/get-started-with-matlab-engine-for-python.html
https://docs.scipy.org/doc/scipy/reference/generated/scipy.io.loadmat.html
https://www.mathworks.com/matlabcentral/answers/427187-problem-with-python-numpy?s_tid=mwa_osa_a
https://www.mathworks.com/help/matlab/matlab_external/passing-data-to-python.html
Please see suggested solutions listed below.
Verify NumPy Installation
- First, ensure that NumPy is indeed installed in your specified Python environment. You can do this by activating your environment and running:
python -m pip show numpy
- If it's not installed, you can install it using:
python -m pip install numpy
Check Python Environment Path
- Make sure that MATLAB is pointing to the correct Python executable. You’ve already set this using:
pyenv("Version", python_env_path);
- Confirm that the environment is loaded properly by checking `pyenv` output after this command.
Using py.importlib.import_module
- Before calling any NumPy functions, explicitly import NumPy in MATLAB:
np = py.importlib.import_module('numpy');
Then, try calling NumPy functions like so:
freq = [0 0.9766 1.9531 2.9297]; py_array = np.array(freq);
Direct Conversion Alternatives
- If you continue to face issues with `py.numpy.array()`, consider converting your data into a compatible format without direct reliance on NumPy. For instance, you can convert MATLAB arrays into Python lists:
freq_list = py.list(num2cell(freq)); % Convert MATLAB array to cell array then to Python list
Please see attached.
Use of pyrun or pyrunfile Functions
- If you have a more complex script or if you need to execute multiple lines of Python code, consider using `pyrun` or `pyrunfile` functions which allow you to run entire scripts and handle outputs effectively.
Also, please review the documentations provided in the links above as well.
Hope following these suggestions should help resolve your problems. Please let me know if you have any further questions.
0 件のコメント
参考
カテゴリ
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!