I'm trying to understand how this work but I'm really confused.
I created a package "parent" under C:\script\test with empty __init__.py
parent\testfunc.py
def return_2():
return 2
Then, a couple sub packages with empty __init__.py
parent\sub\subsub\testsubsub.py
from parent import testfunc
def print_2():
print(testfunc.return_2())
if __name__ == '__main__':
print_2()
- If I execute this within PyCharm, it works. I get 2.
- Open CMD, add C:\script\test to %PATH%, it cannot find the parent module
- CMD with %PATH% set and -m flag, it says I cannot import by filename
Why do I get different result? Why could it not find the package if it's already added to the %PATH%? Why did it work in PyCharm?
Edit - I am unsure if the provided link was addressing the same issue since the OP was able to import his package while I cannot. Additional searching brought me to this thread which suggested %PYTHONPATH% instead of %PATH% and that seems to do the trick.