No module or function named error in Python custom function with MATLAB
Mostrar comentarios más antiguos
Hello
I wish to run Python function from MATLAB command window. I have a set of function in the folder.
To make a seemless integration between the two, I did the following:
pyenv
ans =
PythonEnvironment with properties:
Version: "3.12"
Executable: "C:\Users\poulo\AppData\Local\Programs\Python\Python312\python.exe"
Library: "C:\Users\poulo\AppData\Local\Programs\Python\Python312\python312.dll"
Home: "C:\Users\poulo\AppData\Local\Programs\Python\Python312"
Status: Loaded
ExecutionMode: InProcess
ProcessID: "50204"
ProcessName: "MATLAB"
The output appeared as below:
Next, I added the Python Path using the below command
moduleDirPath = 'C:\pganguli\Pyscripts\atmos-main\atmos-main\atmos\'
insert(py.sys.path, int64(0), moduleDirPath)
It added my package 'atmos' to CPython directory. Now, while checking the dir, it showed all the functions
. __pycache__ moisture.py thermo.py
.. constant.py parcel.py utils.py
__init__.py kinematic.py pseudoadiabat.py
Now, I tried to call my function and I receive No module/function error. The python within MATLAB is working fine, Checked with simple calculation, which is working fine
py.numpy.sqrt([2.0 3.0 4.0])
ans =
Python ndarray:
1.4142 1.7321 2.0000
Kindly let me know where I am missing
P = py.numpy.array(101300); T = py.numpy.array(21.3)
q = py.moisture.specific_humidity_from_dewpoint_temperature(P,T) % specific_humidity_from_dewpoint_temperature is the function available in moisture.py module, which require two variable P & T
No module or function named 'moisture'.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Call Python from MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!