Hi @Poulomi,
I reviewed your Python-MATLAB integration issue and can help you resolve the "No module or function named 'moisture'" error. Let me explain the root cause of error, you have successfully added the atmos folder to Python's path, but you're calling py.moisture.function_name() directly. Since moisture.py is a submodule within the atmos package, Python requires you to reference it through the complete package hierarchy. So, I will suggest following solutions in order of preference
Option 1: Use Full Package Path (Recommended) q = py.atmos.moisture.specific_humidity_from_dewpoint_temperature(P,T)
Option 2: Explicit Module Import py.importlib.import_module('atmos.moisture') q = py.atmos.moisture.specific_humidity_from_dewpoint_temperature(P,T)
Option 3: Fresh MATLAB Session If the above options fail, restart MATLAB to refresh the Python environment: 1. Close MATLAB completely 2. Restart MATLAB 3. Re-execute your setup:moduleDirPath = 'C:\pganguli\Pyscripts\atmos-main\atmos-main\atmos\'insert(py.sys.path, int64(0), moduleDirPath) 4. Try Option 1 again
When you add a package directory to sys.path, Python treats it as a namespace package. Modules within that package must be accessed using dot notation: package.module.function rather than just module.function. So, as quick verification, confirm your package is properly loaded:
py.list(py.sys.path) % Verify your path appears in the list
I will suggest try Option 1 first, it should resolve your issue immediately.
References:
- MathWorks Documentation: "Call User-Defined Python Module" - Shows how to add modules to Python search path and call functions using py.module.function syntax https://www.mathworks.com/help/matlab/matlab_external/call-user-defined-custom-module.html
- MathWorks Documentation: "Call Python from MATLAB" - Official guide for Python integration https://www.mathworks.com/help/matlab/call-python-libraries.html
- MathWorks Documentation: "Python with MATLAB" - Comprehensive guide for calling Python library functionality from MATLAB https://www.mathworks.com/help/matlab/python-language.html
Let me know if you need any clarification!