matlab.engine ImportError
I wanted to call Matlab from Python using the matlab engine. I’m on Macbook Air M3 chip. I have successfully done so and this is a brief summary of the setup:
I used Matlab R2024a Apple Silicon version and Python 3.9.
I created an environment (mac_apple for short) using Anaconda and installed matlab engine by ‘pip install matlabengine==24.1.2’.
I use Spyder as IDE. I was able to import and use the matlab engine without any problem.
Now, I need to use an essential Python pkg, and it is only compatible with the x86 architecture but not the ARM architechture. To work around this:
I created a new environment (mac_86 for short) using Anaconda but configured it to use the x86 architecture by ‘conda config –env –set subdir osx-64’.
I installed the Matlab R2024b Intel version on the same machine. This is because I think when installing matlab engine to this env it will be pulled from the x86 architechture, so I need to install a x86 version (or Intel version) Matlab. I chose a different version than R2024a so that I can install the R2024b in the default location, which I think may save me from some trouble.
Then I installed matlab engine by ‘python -m pip install matlabengine==24.1.2’ (the command recommded by https://pypi.org/project/matlabengine/, I didn’t use this the first time because I wasn’t aware of this recommendation).
In Spyder I switched the Python Interpreter to this new env, but I got ImportError when importing matlab engine. Please see screenshot below. The error message looks like the paths all point to the Apple Silicon version of Malab not the Intel Version.
By any chance, could any one help me figure this out? I don’t understand why this is happening as I’m following pretty much the same procedure I used before. If possible, I’d like a solution that allows me to make both environments work, i.e., use x86-based matlabengine in mac_86 and use Apple silicon-based matlabengine in mac_apple. Thank you in advance!I wanted to call Matlab from Python using the matlab engine. I’m on Macbook Air M3 chip. I have successfully done so and this is a brief summary of the setup:
I used Matlab R2024a Apple Silicon version and Python 3.9.
I created an environment (mac_apple for short) using Anaconda and installed matlab engine by ‘pip install matlabengine==24.1.2’.
I use Spyder as IDE. I was able to import and use the matlab engine without any problem.
Now, I need to use an essential Python pkg, and it is only compatible with the x86 architecture but not the ARM architechture. To work around this:
I created a new environment (mac_86 for short) using Anaconda but configured it to use the x86 architecture by ‘conda config –env –set subdir osx-64’.
I installed the Matlab R2024b Intel version on the same machine. This is because I think when installing matlab engine to this env it will be pulled from the x86 architechture, so I need to install a x86 version (or Intel version) Matlab. I chose a different version than R2024a so that I can install the R2024b in the default location, which I think may save me from some trouble.
Then I installed matlab engine by ‘python -m pip install matlabengine==24.1.2’ (the command recommded by https://pypi.org/project/matlabengine/, I didn’t use this the first time because I wasn’t aware of this recommendation).
In Spyder I switched the Python Interpreter to this new env, but I got ImportError when importing matlab engine. Please see screenshot below. The error message looks like the paths all point to the Apple Silicon version of Malab not the Intel Version.
By any chance, could any one help me figure this out? I don’t understand why this is happening as I’m following pretty much the same procedure I used before. If possible, I’d like a solution that allows me to make both environments work, i.e., use x86-based matlabengine in mac_86 and use Apple silicon-based matlabengine in mac_apple. Thank you in advance! I wanted to call Matlab from Python using the matlab engine. I’m on Macbook Air M3 chip. I have successfully done so and this is a brief summary of the setup:
I used Matlab R2024a Apple Silicon version and Python 3.9.
I created an environment (mac_apple for short) using Anaconda and installed matlab engine by ‘pip install matlabengine==24.1.2’.
I use Spyder as IDE. I was able to import and use the matlab engine without any problem.
Now, I need to use an essential Python pkg, and it is only compatible with the x86 architecture but not the ARM architechture. To work around this:
I created a new environment (mac_86 for short) using Anaconda but configured it to use the x86 architecture by ‘conda config –env –set subdir osx-64’.
I installed the Matlab R2024b Intel version on the same machine. This is because I think when installing matlab engine to this env it will be pulled from the x86 architechture, so I need to install a x86 version (or Intel version) Matlab. I chose a different version than R2024a so that I can install the R2024b in the default location, which I think may save me from some trouble.
Then I installed matlab engine by ‘python -m pip install matlabengine==24.1.2’ (the command recommded by https://pypi.org/project/matlabengine/, I didn’t use this the first time because I wasn’t aware of this recommendation).
In Spyder I switched the Python Interpreter to this new env, but I got ImportError when importing matlab engine. Please see screenshot below. The error message looks like the paths all point to the Apple Silicon version of Malab not the Intel Version.
By any chance, could any one help me figure this out? I don’t understand why this is happening as I’m following pretty much the same procedure I used before. If possible, I’d like a solution that allows me to make both environments work, i.e., use x86-based matlabengine in mac_86 and use Apple silicon-based matlabengine in mac_apple. Thank you in advance! matlab engine, python, mac MATLAB Answers — New Questions