When I try running my Python module with the form py -m foldername, I get a ModuleNotFoundError referencing a different module that I am importing that I have also written. It runs perfectly fine if I just write py modulename.py, but not with the -m. Why is the module not found when called through -m but is found otherwise? Thanks!
Minimum reproducible example:
All files are in foldername
File __main__.py
import m
m.p()
File m.py
def p():
print("hello")
Here is the full error
C:\Users\g\Documents>py -m hello Traceback (most recent call last): File "C:\Users\g\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\g\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "C:\Users\g\Documents\hello\__main__.py", line 1, in import m ModuleNotFoundError: No module named 'm'