473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

py2exe 0.5.0 and data_files

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.

Thanks in advance for any comments,

Ulrich
Jul 18 '05 #1
5 2970
Try the following...

ex_name = 'myprogram.exe'

if sys.path[0][-len(ex_name):] == ex_name:
path = os.path.split(sys.path[0])
else:
path = os.path.split(__file__)

I don't know if the above works correctly when the script is not a part
of an executable, but is imported with zipimport.

- Josiah
Jul 18 '05 #2
Josiah Carlson <jc******@nospam.uci.edu> writes:
Try the following [...]


Thanks for your suggestion. I see that I can get around this
problem by analyzing sys.path[0] and proceeding case by case.
However, my understanding is that it should not be necessary
for the application to "know" that it will be packaged by
py2exe later. In other words, why does py2exe "change"
sys.path[0]? Or, if this change is justified (and it may well
be), maybe my application shpuld not use sys.path[0] but a
different way to find out the path where it resides?

In addition, since this change in the behavior of py2exe forces
me to change the Python application which I want to package
itself, I am asking myself whether there are other changes that
have to be made but which are not as obvious as this one.

(All this is not meant as criticism towards py2exe; it is a
great program. But I would like to improve my understanding
of its behavior, and of what is the right thing to do in my
application.)

Ulrich
Jul 18 '05 #3
> Thanks for your suggestion. I see that I can get around this
problem by analyzing sys.path[0] and proceeding case by case.
However, my understanding is that it should not be necessary
for the application to "know" that it will be packaged by
py2exe later. In other words, why does py2exe "change"
sys.path[0]? Or, if this change is justified (and it may well
be), maybe my application shpuld not use sys.path[0] but a
different way to find out the path where it resides?
sys.path[0] has different meanings depending on the context. These are
the two cases I've come across. While there could be more,

In addition, since this change in the behavior of py2exe forces
me to change the Python application which I want to package
itself, I am asking myself whether there are other changes that
have to be made but which are not as obvious as this one.
It is possible, but doubtful. I use this same method for PyPE
(http://pype.sf.net), and aside from people using paths with unicode
characters in them, I've had few (if any) issues with source vs.
executable compatibility. There is one outstanding issue, but the bug
reports haven't specified what are the conditions of the 'error', only
that a certain set of related features don't work.

(All this is not meant as criticism towards py2exe; it is a
great program. But I would like to improve my understanding
of its behavior, and of what is the right thing to do in my
application.)


Special case the finding of the running path, and work from there.

- Josiah
Jul 18 '05 #4
Ulrich Goertz <u@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
Jul 18 '05 #5
Thomas Heller <th*****@python.net> writes:
Ulrich Goertz <u@g0ertz.de> writes:
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'.
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.


Thanks for the pointer! I had briefly looked at the setup.py script in
samples/simple before, but not at hello.py itself ...

Thanks for writing py2exe, and kind regards,

Ulrich
Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ulysses | last post by:
hi. I use python 23,py2exe 0.4.3 ,wxpython do my py app in win32. I use gettext to support multi languages. I build a small fuction for load language at top of main module....
3
by: Werner Merkl | last post by:
Hi, Python is really great, for small to big programs. For my colleagues and some circumstances I sometimes need to "compile" a script using py2exe. Cause I use Windows, I like to use the...
2
by: Bryan | last post by:
just for fun and my own experience, i wanted to use py2exe to wrap the wxpython demo. i put the setup script in the demo directory which is the following: from distutils.core import setup...
4
by: Werner Merkl | last post by:
Hi, we have written a Python EXE program, which should run via AUTORUN.INF from a CD/DVD (Windows of course). For this CD/DVD we us a imaging tool from Microsoft, which seam to generate...
8
by: PipedreamerGrey | last post by:
I've been banging my head against this problem for a week. It's time to ask for help, because I'm obviously not going to solve this by trial and error. I'm trying to create a standalone version...
4
by: bwaha | last post by:
First time trying to create an executable with py2exe. I have a small program which makes use of python23 (2.3.5?), wxpython ('2.6.2.1'), matplotlib ('0.83.2'), win32com (latest?), Numeric...
3
by: vajratkarviraj | last post by:
i hav python2.5, matplotlib0.90.1, and py2exe for python 2.5 all on windows xp... i hav a python program(letsc.py) which uses the matplotlib package... and i want 2 make an exe of it for distribution...
0
by: devnew | last post by:
I wrote an app that uses some Tix widgets and wanted to make an exe using py2exe .i used the setup script as given in http://www.py2exe.org/index.cgi/TixSetup and it copies the dlls into the dist...
0
by: PamMish1982 | last post by:
Hi all, I have recently started using Python and I am trying to make a GUI out of Tkinter. I am using matplotlib for the graphic purposes. I have to make a exe file from this code. I use py2exe...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.