Use $PWD for cwd before attempting getcwd() .

os.getcwd() follows symlinks and hence is not the same path as
returned from $PWD, which is more commonly used in the shell
prompt.