Get EXE (made with py2exe) path directory name

Andrei B andreizilla at
Tue Jun 6 03:26:28 CEST 2006

I need to get absolute path name of a file that's in the same dir as
the exe, however the Current Working Directory is changed to somthing

I turn my script into an executable with py2exe, then I create a
shortcut to the EXE on the desktop. I change the "Start In" variable of
the shortcut "C:\somthing_else", so now the currect working directory
of the executable is not the same as the directory where the EXE is

I need to load a file that's in the same directory as the EXE, so I do
the following:

dir = os.path.dirname(sys.argv[0])
filepath = os.path.join(dir, 'server.pkey')

however it doesn't seem to work.

Any idea?


More information about the Python-list mailing list