py2exe 0.5.0 and data_files

Thomas Heller theller at python.net
Sat Mar 20 11:10:25 EST 2004


Ulrich Goertz <u at g0ertz.de> writes:

> Hello,
>
> I am trying to understand how py2exe 0.5.0 deals with data files. 
> My application tries to access certain data files via sys.path[0]
> (e.g. the file 'menus.def' which lies in the same path as the
> python script (or the .exe which py2exe produces, respectively)
> is accessed via os.path.join(sys.path[0],'menus.def').
>
> Now I have the data files which I need in the data_files list given
> as an argument to the setup method, and py2exe does copy them to
> the dist subdirectory all right. However, sys.path[0] is not the 
> path where the program resides, but the path + 'library.zip'.
>
> Is there an elegant way to proceed? Of course, I could remove the
> 'library.zip' to find the actual path, but that somehow does not 
> look like the 'right thing'. I would prefer a solution which works
> for the genuine Python script (not packaged by py2exe) as well as 
> for the .exe.

There is a sample 'hello.py' in the py2exe\samples\simple subdirectory,
which lets you explore the differences between the normal Python script,
and the executable.  I don't have time now - more later.

Thomas





More information about the Python-list mailing list