Import Error calling Python function from Matlab

조회 수: 5 (최근 30일)
Chinenye Ezeh
Chinenye Ezeh 2019년 4월 2일
답변: Luis J Gilarranz 2020년 4월 6일
I need to call Modularity-Density Measure which is a Python function from Matlab to enable me determine the quality of network communities detected by an algorithm I designed. I tried so much without success to call the python function but each time, I end up with error messages even when I follow the examples on Mathworks's Python import and Matlab import. Let me state the examples and then show what I did.
import py.textwrap.wrap
S = wrap('This is a string');
The code above works fine but when I do same thing I get error message.
import py.modularitydensity.fine_tuned_modularity_density
%Error using import: Import argument 'py.modularitydensity.fine_tuned_modularity_density' cannot be found or cannot be imported.
I then tried the 'py.importlib.import_module' command.
py.importlib.import_module('modularitydensity.fine_tuned_modularity_density', 'modularity_density')
It returned the following results:
%Python module with properties:
%fiedler_vector: [1×1 py.function]
%np: [1×1 py.module]
%fine_tuned_clustering_qds: [1×1 py.function]
%merge_communities_qds: [1×1 py.function]
%split_communities_qds: [1×1 py.function]
%modularity_density: [1×1 py.function]
%not_implemented_for: [1×1 py.function]
%nx: [1×1 py.module]
Then I tried to implement the target function 'modularity_density' but I end up with error messages.
py.modularity_density(A)
%Undefined variable "py" or class "py.modularity_density".
I tried these other commands:
!E:\python\python.exe modularity_density.py A
%E:\python\python.exe: can't open file 'modularity_density.py': [Errno 2] No such file or directory
!E:\python\python.exe fine_tuned_modularity_density.py A
%Traceback (most recent call last):
%File "fine_tuned_modularity_density.py", line 17, in <module>
%from metrics import modularity_density
%File "E:\matlab\bin\from github\similarity\modularity-density-master\modularity-density-master\src\modularitydensity\metrics.py", line 10, in <module>
%from scipy.sparse import identity
%ImportError: No module named scipy.sparse
None of the commands give results and I don't understand what I have been doing wrong. Any advice and assistance to help me get this code working is highly appreciated.
Thanks.
link to the modularity density Python package: Modularity_Density Python Package

답변 (1개)

Luis J Gilarranz
Luis J Gilarranz 2020년 4월 6일

카테고리

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

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by