the notion of the current working directory (cwdturns out to be key concept in some scriptsexecutionit' always the implicit place where files processed by the script are assumed to reside unless their names have absolute directory paths as we saw earlieros getcwd lets script fetch the cwd name explicitlyand os chdir allows script to move to new cwd keep in mindthoughthat filenames without full pathnames map to the cwd and have nothing to do with your pythonpath setting technicallya script is always launched from the cwdnot the directory containing the script file converselyimports always first search the directory containing the scriptnot the cwd (unless the script happens to also be located in the cwdsince this distinction is subtle and tends to trip up beginnerslet' explore it in bit more detail cwdfilesand import paths when you run python script by typing shell command line such as python dir \dir \file pythe cwd is the directory you were in when you typed this commandnot dir \dir on the other handpython automatically adds the identity of the script' home directory to the front of the module search path such that file py can always import other files in dir \dir no matter where it is run from to illustratelet' write simple script to echo both its cwd and its module search pathc:\pp \systemtype whereami py import ossys print('my os getcwd =>'os getcwd()print('my sys path =>'sys path[: ]input(show my cwd execution dir show first import paths wait for keypress if clicked nowrunning this script in the directory in which it resides sets the cwd as expected and adds it to the front of the module import search path we met the sys path module search path earlierits first entry might also be the empty string to designate cwd when you're working interactivelyand most of the cwd has been truncated to here for displayc:\pp \systemset pythonpath= :\pp thed\examples :\pp \systempython whereami py my os getcwd = :\pp \system my sys path =[' :\\\pp \\system'' :\\pp thed\\examples'more but if we run this script from other placesthe cwd moves with us (it' the directory where we type commands)and python adds directory to the front of the module search path that allows the script to still see files in its own home directory for instancewhen running from one level up )the system name added to the front of sys path will be the first directory that python searches for imports within whereami pyit points imports back to the directory containing the script that was run filenames without script execution context