필터 지우기
필터 지우기

Matlab Engine for Python Installation Issue - usage with Miniconda and PowerShell

조회 수: 3 (최근 30일)
I am using python 3.9 from miniconda on my windows machine. I installed the matlab engine as suggested in the official guide, trying with and without:
--prefix="C:\ProgramData\Miniconda3"
Opening a PowerShell I can type in
python
import matlab.engine
and it works. However, this is not working in the Spyder IPython console. Similarly, I would like to have working the following command in a powershell (as it is passed by VSCode short cut):
& C:/ProgramData/Miniconda3/python.exe c:/Users/python_script_to_run_matlab_code.py
I guess that is the same issue like in the Spyder IPython console. Possibly, the issue could be that the matlab engine is not installed to the right python installation/environment (although I use only that one installed python 3.9 from miniconda).
Any suggestions how to change my installations?
PS: If I type
conda list matlab
to the powershell where I want to run the above python command (starting with "& C:/ProgramData/..."), I receive "matlabengineforpython" which fits to the folder "matlabengineforpython-R2021b-py3.9.egg" in "C:\ProgramData\Miniconda3\Lib\site-packages".

답변 (1개)

Debadipto
Debadipto 2023년 9월 1일
Hello @Steffen,
I understand you have successfully installed the MATLAB engine for Python in your Miniconda environment and it works in the PowerShell environment. However, you are encountering issues when trying to use it in the Spyder IPython console or running a Python script that invokes MATLAB from PowerShell.
To resolve this issue, you can try the following steps:
1. Ensure that Spyder is configured to use the correct Python interpreter. Open Spyder and go to "Tools" > "Preferences" > "Python Interpreter". Make sure that the interpreter selected is the one from your Miniconda environment, where you have installed the MATLAB engine. If it's not listed, you may need to add it manually.
2. If Spyder is already configured correctly, try restarting Spyder and see if the MATLAB engine works in the IPython console.
3. If the issue persists, you can try running the Python script from PowerShell using the Miniconda environment explicitly. Open the PowerShell and activate your Miniconda environment by running the following command:
conda activate <your-environment-name>
Replace `<your-environment-name>` with the name of your Miniconda environment.
After activating the environment, navigate to the directory where your Python script is located and run the script using the Python interpreter from the Miniconda environment:
& C:/ProgramData/Miniconda3/envs/<your-environment-name>/python.exe c:/Users/python_script_to_run_matlab_code.py
Replace `<your-environment-name>` with the name of your Miniconda environment. This ensures that the script is executed within the correct Miniconda environment where the MATLAB engine is installed.

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by