My main file is this:
/Users/ljh/Documents/helloPy/src/appdir/__main__.py
sys.path[0] return different value when I run the script file with only the dir and without the basename of the file.
I think the reliable way is to always run the script specifying the basename.
print('1', os.path.realpath(sys.argv[0]))
print('2', os.path.realpath(sys.path[0]))
$ python3 appdir
1 /Users/ljh/Documents/helloPy/src/appdir
2 /Users/ljh/Documents/helloPy/src/appdir
$
$ python3 -m appdir
1 /Users/ljh/Documents/helloPy/src/appdir/__main__.py
2 /Users/ljh/Documents/helloPy/src
$