Matlab Engine for Python Installation Issue - usage with Miniconda and PowerShell
6 次查看(过去 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".
0 个评论
回答(1 个)
Debadipto
2023-9-1
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call Python from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!