Reputation: 705
I want to use MATLAB in Python and I want to exchange data between Python and MATLAB. Since there is no "matlab.engine" in the repository search, then how do I install the matlab.engine in Pycharm? The other question how do I install a local package in Pycharm?
Upvotes: 1
Views: 4641
Reputation: 705
This question is very useful for the MATLAB-Python beginners working in Pycharm. After you compile your MATLAB code into a Python package you require to introduce it to the Python. If you are coding in Pycharm (which is very popular) then it becomes to somehow tricky. I consider two types of MATLAB applications in this context. First are the applications that take no input from the master Python file. In this case, in Pycharm, go to File--> Settings --> Gear --> More --> Show all --> Show paths to the selected interpreter --> here insert the directory of the MATLAB-compiled package. But using Matlab.engine is very essential and in most of the cases, you require exchange data between Python and MATLAB. There is no direct way to introduce Pycharm the Matlab.engine
For this, go to "edit environmental variables" and insert such address at the top:
C:\MyPythonApplication\venv\scrips
By this action, we will tell the windows to consider the python.exe file inside the Python application folder to create and setup prerequisites of the MATLAB.engine
Then open cmd running as administrator and go to your root MATLAB installation directory and find such directory:
cd C:\Program Files\MATLAB\R2018a\extern\engines\python\build\lib
Then type :
python setup.py install
Go back to "edit environmental variables" and delete the address you had inserted address at the top.
In Pycharm type:
import matlab.egine
Compile and it will exit the process with code 0
Good luck
Upvotes: 0