472,971 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

In search of idiom in py2exe

In many of my scripts I've used the following idiom for accessing data
files placed nearby:

BASEDIR = os.path.dirname(__file__)
..
..
..
fp = file(os.path.join(BASEDIR,"somefile.txt"))
..
..
..
img = image.open(os.path.join(BASEDIR,"images","someimag e.jpg"))
This works well with my cohorts who place their work on different
drives, in different directories, etc.

However, when I use py2exe to make an executable, the name '__file__'
is not defined.

Can anyone recommend an idiom that will work with py2exe?

Thanks in advance,
Dave M.

P.S. -- We've also tried the idiom

BASEDIR = os.path.dirname(sys.argv[0])

but the result can be misleading, for example, if the script is
launched from a desktop shortcut.
Jul 18 '05 #1
3 1888
David wrote:
In many of my scripts I've used the following idiom for accessing data
files placed nearby: .... Can anyone recommend an idiom that will work with py2exe?


Do the last few posts to the following thread help you? It
was an attempt to find "the" idiomatic way to find the
directory of the main script, whether running normally or
with py2exe.

http://groups.google.ca/groups?threa...ing.google.com

-Peter
Jul 18 '05 #2
On Tue, 07 Sep 2004 22:08:21 -0400, Peter Hansen <pe***@engcorp.com>
wrote:

Thanks! That's the ticket.
David wrote:
In many of my scripts I've used the following idiom for accessing data
files placed nearby:

...
Can anyone recommend an idiom that will work with py2exe?


Do the last few posts to the following thread help you? It
was an attempt to find "the" idiomatic way to find the
directory of the main script, whether running normally or
with py2exe.

http://groups.google.ca/groups?threa...ing.google.com

-Peter


Jul 18 '05 #3
After struggling with this for a while I came up with
what method that ALWAYS works for me. I use some sort
of .INI configuration file in almost 100% of my programs
(particularly the ones that I "freeze" with py2exe). I
routinely put a parameter in that .INI file that is
something like:

[defaults]
installpath=<installer will update this line>
..
.. Followed by other .INI configuration parameters
..

Then I put a lines in my Inno Installer script that are
something like:

[INI]
;
; Set the paths in progfile.INI to point to where the
; program was installed
;
Filename: "{app}\progfile.ini"; Section: "defaults";
Key: "installpath"; String: "{app}" (all on 1 line)

This allows the user to install the application anywhere
they wish AND I have a foolproof way of finding my way
back to the program file's installation directory. May
not be as elegant as some other approaches but it is
easily understandable and seems to work 100% of the time.

Larry Bates
Syscon, Inc.
<David Morgenthaler> wrote in message
news:dq********************************@4ax.com...
In many of my scripts I've used the following idiom for accessing data
files placed nearby:

BASEDIR = os.path.dirname(__file__)
.
.
.
fp = file(os.path.join(BASEDIR,"somefile.txt"))
.
.
.
img = image.open(os.path.join(BASEDIR,"images","someimag e.jpg"))
This works well with my cohorts who place their work on different
drives, in different directories, etc.

However, when I use py2exe to make an executable, the name '__file__'
is not defined.

Can anyone recommend an idiom that will work with py2exe?

Thanks in advance,
Dave M.

P.S. -- We've also tried the idiom

BASEDIR = os.path.dirname(sys.argv[0])

but the result can be misleading, for example, if the script is
launched from a desktop shortcut.

Jul 18 '05 #4

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

Similar topics

0
by: RJS | last post by:
Hi all, I can't get a py2exe compiled app to run with numarray (numarray-0.5.win32- py2.2). Also wxPythonWIN32-2.3.3.1-Py22 and ActivePython-2.2.1-222. In the sample below, commenting out...
1
by: | last post by:
I want a binnary file to my aplicattion, but py2exe don't match the xmll.sax module. the py2exe shows this errors: warning: py2exe:...
2
by: Stefan Behrens | last post by:
Hi, does anybody know how I can get py2exe to work with wxPython's wxCalendarCtrl? Currently, I have just a "standard" setup.py, and py2exe gives me a syntax error. Do I need to include any...
8
by: Kathleen Kudzma | last post by:
Does anyone know how to resolve the following problem that I'm getting in Python 2.2 and 2.3? PROBLEM: When I try to create a classReader object I get an exception: "SAXReaderNotAvailable: No...
0
by: Steven Bell | last post by:
I am trying to build an executable from a python script. Using python 2.3, SOAPpy 0.10.3, Py2exe 0.4.2. Build command: python setup.py py2exe -w --includes xml.sax.drivers2.drv_py I get the...
6
by: Luc Saffre | last post by:
Hello, I had a strange problem when freezing (using either py2exe or McMillan installer) a script that imports reportlab (which imports PIL (which imports FixTk))). - Python 2.3.3c (also with...
2
by: Ola K | last post by:
Hi guys, I wrote a script that works *almost* perfectly, and this lack of perfection simply puzzles me. I simply cannot point the whys, so any help on it will be appreciated. I paste it all here,...
0
by: Larry Bates | last post by:
Jimmy Retzlaff wrote: Everyone, Thanks for all your hard work on py2exe, it is greatly appreciated. -Larry Bates
0
by: Jimmy Retzlaff | last post by:
py2exe 0.6.9 released ===================== py2exe is a Python distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.