Failed to import compiled matlab package in python
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi All,
I was trying to import a compiled matlab package in python, and it raises error ModuleNotFoundError: No module named 'matlabruntimeforpython3_6'. What could be the reason?
Details:
I followed the instruction in https://www.mathworks.com/help/compiler_sdk/ml_code/create-a-python-application-with-matlab-code.html , and installed the generated package by running python setup.py install , in the dir `<package>\for_redistribution_files_only`
The install info reads:
running install
running build
running build_py
creating build
creating build\lib
creating build\lib\FRF_train_test
copying FRF_train_test\__init__.py -> build\lib\FRF_train_test
copying FRF_train_test\FRF_train_test.ctf -> build\lib\FRF_train_test
running install_lib
running install_egg_info
Removing C:\Users\Ruibo\Anaconda3\envs\nondeeplearning\Lib\site-packages\matlabruntimeforpython-R2020a-py3.6.egg-info
Writing C:\Users\Ruibo\Anaconda3\envs\nondeeplearning\Lib\site-packages\matlabruntimeforpython-R2020a-py3.6.egg-info
removing 'build\lib' (and everything under it)
'build\bdist.win-amd64' does not exist -- can't clean it
'build\scripts-3.6' does not exist -- can't clean it
removing 'build'
and when I try to import the package by its name in python , it gives the error message as
Traceback (most recent call last):
File "d:\Topo_Regression\topological_regression\FRF_train_test\for_redistribution_files_only\samples\FRF_train_testSample1.py", line 10, in <module>
import FRF_train_test
File "C:\Users\Ruibo\Anaconda3\envs\nondeeplearning\lib\site-packages\FRF_train_test\__init__.py", line 283, in <module>
_pir.import_cppext()
File "C:\Users\Ruibo\Anaconda3\envs\nondeeplearning\lib\site-packages\FRF_train_test\__init__.py", line 276, in import_cppext
self.cppext_handle = importlib.import_module("matlabruntimeforpython" + self.interpreter_version)
File "C:\Users\Ruibo\Anaconda3\envs\nondeeplearning\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'matlabruntimeforpython3_6'
Could any one help me with identifying what could be the reason?
0 Kommentare
Antworten (1)
Harshit
am 15 Sep. 2023
Hello,
I understand that you encountered an error while trying to import the "matlab.engine" module in Python.
To resolve this issue, you need to modify the "PYTHONPATH" environment variable to include the directory where MATLAB Engine is installed. In this case, ensure that the first path in the "PYTHONPATH" variable is set to a location similar to the following: "C:\Users\username\AppData\Local\Programs\Python\Python36\Lib\site-packages\matlab\engine".
By updating the "PYTHONPATH" variable, the required modules will be searched in the correct location during import.
If this doesn't solve the issue, you can try running Python in verbose mode when importing the module. Start Python in verbose mode using the command "python -vvv". This will provide more detailed information about the import process and may help identify any underlying issues.
Regards,
Harshit
0 Kommentare
Siehe auch
Kategorien
Mehr zu Python Package Integration finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!