473,396 Members | 2,002 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,396 software developers and data experts.

py2exe windows apps path question

I have several python apps (some wxPython, some plain text-mode
stuff) that I distribute internally for installation on Win32
machines. They're bundled/installed using py2exe and inno
setup.

I followed what I think is the normal procedure of installing
each app in its own directory under /Program
Files/<vendor>/<app>.

The problem is that the apps only run if they're started with
the install directory as the current working directory.
Otherwise they can't find the .dll's they use from the install
directory.

Is there some way to temporarily add the app's install
directory to the search path for .dll's?

--
Grant Edwards grante Yow! .. I think I'd
at better go back to my DESK
visi.com and toy with a few common
MISAPPREHENSIONS...
Aug 2 '05 #1
9 2116

"Grant Edwards" <gr****@visi.com> schrieb im Newsbeitrag
news:11************@corp.supernews.com...
|I have several python apps (some wxPython, some plain text-mode
| stuff) that I distribute internally for installation on Win32
| machines. They're bundled/installed using py2exe and inno
| setup.
|
| I followed what I think is the normal procedure of installing
| each app in its own directory under /Program
| Files/<vendor>/<app>.
|
| The problem is that the apps only run if they're started with
| the install directory as the current working directory.
| Otherwise they can't find the .dll's they use from the install
| directory.

AFAIK, Windows normally *does* search the directory where the executable
module for the current process lives in for dlls. What sort of dlls are
given you trouble?

--

Vincent Wehren


|
| Is there some way to temporarily add the app's install
| directory to the search path for .dll's?
|
| --
| Grant Edwards grante Yow! .. I think I'd
| at better go back to my
DESK
| visi.com and toy with a few
common
| MISAPPREHENSIONS...
Aug 2 '05 #2
Vincent, I'm not sure I completely understand your question but this
link may be the answer nonetheless:
http://www.jrsoftware.org/isfaq.php#workingdir

And here is how I make sure I'm always using the right directory in my scripts:

Put this code at the top:
import sys
curdir=os.path.dirname(sys.argv[0])
#print curdir
Then I use curdir to build all of the paths in my app:
For example let's get a list of files in a folder:
lstresumes=os.listdir(os.path.join(curdir,resume_f older_path)) #get
list of resumes
Below is optional but helps me keep a python module in the exe's main
directory and be able to edit it. Otherwise the main module reads
from py2exe's lib file which seems harder to change:
sys.path.insert(0,curdir) #read usersettings.py from main dir, not library
Let me know if that helps (I may be answering the question I had
yesterday and not yours though ;-)

-Greg
On 8/2/05, vincent wehren <vi*****@visualtrans.de> wrote:

"Grant Edwards" <gr****@visi.com> schrieb im Newsbeitrag
news:11************@corp.supernews.com...
|I have several python apps (some wxPython, some plain text-mode
| stuff) that I distribute internally for installation on Win32
| machines. They're bundled/installed using py2exe and inno
| setup.
|
| I followed what I think is the normal procedure of installing
| each app in its own directory under /Program
| Files/<vendor>/<app>.
|
| The problem is that the apps only run if they're started with
| the install directory as the current working directory.
| Otherwise they can't find the .dll's they use from the install
| directory.

AFAIK, Windows normally *does* search the directory where the executable
module for the current process lives in for dlls. What sort of dlls are
given you trouble?

--

Vincent Wehren




|
| Is there some way to temporarily add the app's install
| directory to the search path for .dll's?
|
| --
| Grant Edwards grante Yow! .. I think I'd
| at better go back to my
DESK
| visi.com and toy with a few
common
| MISAPPREHENSIONS...


--
http://mail.python.org/mailman/listinfo/python-list

--
Gregory Piñero
CEO and Founder
Blended Technologies
(www.blendedtechnologies.com)
Aug 2 '05 #3
On 8/2/05, Gregory Piñero <gr********@gmail.com> wrote:
Vincent, I'm not sure I completely understand your question but this
link may be the answer nonetheless:
http://www.jrsoftware.org/isfaq.php#workingdir


I meant to say Grant, ... , Vincent wasn't the one with the question. Sorry.
Aug 2 '05 #4
On 2005-08-02, vincent wehren <vi*****@visualtrans.de> wrote:

"Grant Edwards" <gr****@visi.com> schrieb im Newsbeitrag
news:11************@corp.supernews.com...
|I have several python apps (some wxPython, some plain text-mode
| stuff) that I distribute internally for installation on Win32
| machines. They're bundled/installed using py2exe and inno
| setup.
|
| I followed what I think is the normal procedure of installing
| each app in its own directory under /Program
| Files/<vendor>/<app>.
|
| The problem is that the apps only run if they're started with
| the install directory as the current working directory.
| Otherwise they can't find the .dll's they use from the install
| directory.

AFAIK, Windows normally *does* search the directory where the executable
module for the current process lives in for dlls. What sort of dlls are
given you trouble?


One's a "driver" for a CAN bus USB widget. The other failure
that springs to mind is that gnuplot-py couldn't find something
(could have been an .exe) that was in the app directory.

--
Grant Edwards grante Yow! HUGH BEAUMONT died
at in 1982!!
visi.com
Aug 2 '05 #5
"Gregory Piñero" <gr********@gmail.com> schrieb im Newsbeitrag
news:ma***************************************@pyt hon.org...

|And here is how I make sure I'm always using the right directory in my
scripts:
|
|Put this code at the top:
|import sys
|curdir=os.path.dirname(sys.argv[0])
|#print curdir
|Then I use curdir to build all of the paths in my app:
|For example let's get a list of files in a folder:
|lstresumes=os.listdir(os.path.join(curdir,resume_ folder_path)) #get
|list of resumes

<snipped>

Greg,

If you need something that works both on a frozen app as well as an
(unfrozen) python
script, you'd be better off using something like:

def getAppPrefix():
"""Return the location the app is running from
"""
isFrozen = False
try:
isFrozen = sys.frozen
except AttributeError:
pass
if isFrozen:
appPrefix = os.path.split(sys.executable)[0]
else:
appPrefix = os.path.split(os.path.abspath(sys.argv[0]))[0]
return appPrefix

Now you can use the return value of getAppPrefix() everywhere you need to
calculate paths relative to your app, regardless if it involves a regular
script or py2exe'ified one.

Regards,

--

Vincent Wehren
Aug 2 '05 #6
"Grant Edwards" <gr****@visi.com> schrieb im Newsbeitrag
news:11*************@corp.supernews.com...
| On 2005-08-02, vincent wehren <vi*****@visualtrans.de> wrote:
| >
| > "Grant Edwards" <gr****@visi.com> schrieb im Newsbeitrag
| > news:11************@corp.supernews.com...
| >|I have several python apps (some wxPython, some plain text-mode
| >| stuff) that I distribute internally for installation on Win32
| >| machines. They're bundled/installed using py2exe and inno
| >| setup.
| >|
| >| I followed what I think is the normal procedure of installing
| >| each app in its own directory under /Program
| >| Files/<vendor>/<app>.
| >|
| >| The problem is that the apps only run if they're started with
| >| the install directory as the current working directory.
| >| Otherwise they can't find the .dll's they use from the install
| >| directory.
| >
| > AFAIK, Windows normally *does* search the directory where the executable
| > module for the current process lives in for dlls. What sort of dlls are
| > given you trouble?
|
| One's a "driver" for a CAN bus USB widget. The other failure
| that springs to mind is that gnuplot-py couldn't find something
| (could have been an .exe) that was in the app directory.

Grant,

If you are building paths in you code that are relative to your app, please
see my reply to Greg's post. If not, you may as a workaround want to try to
add the frozen application's directory to the system path environment
variable. Windows will look for dlls there, too.

To get the app's actual location, you will need something like the
getAppPrefix() function as per my reply to Greg's reply. The getAppPrefix()
function will also hold when the user adds your frozen app to his/her system
path and call the app from any location from the command line - sys.argv[0]
just won't do the trick in such a setting.
HTH,

--

Vincent Wehren




|
| --
| Grant Edwards grante Yow! HUGH BEAUMONT
died
| at in 1982!!
| visi.com
Aug 2 '05 #7
> If you need something that works both on a frozen app as well as an
(unfrozen) python
script, you'd be better off using something like:

def getAppPrefix():
"""Return the location the app is running from
"""
isFrozen = False
try:
isFrozen = sys.frozen
except AttributeError:
pass
if isFrozen:
appPrefix = os.path.split(sys.executable)[0]
else:
appPrefix = os.path.split(os.path.abspath(sys.argv[0]))[0]
return appPrefix


Vincent,

This sounds interesting. A few questions for you:
Why don't I see sys.frozen in interpreter?
Does it only appear when it is frozen?
What do you mean by frozen, how does python know?
What does sys.executable do?

Thanks,

Greg
Aug 2 '05 #8
On 2005-08-02, vincent wehren <vi*****@visualtrans.de> wrote:
If you are building paths in you code that are relative to
your app,
I'm not using any paths. I use cytpes to load a .dll, and I
don't really know what gnuplot-py is doing, but I think it's
executing a .exe file and talking to it via a pipe or something.
please see my reply to Greg's post. If not, you may
as a workaround want to try to add the frozen application's
directory to the system path environment variable. Windows
will look for dlls there, too.
That's probably the right answer.
To get the app's actual location, you will need something like
the getAppPrefix() function as per my reply to Greg's reply.
The getAppPrefix() function will also hold when the user adds
your frozen app to his/her system path and call the app from
any location from the command line - sys.argv[0] just won't do
the trick in such a setting.


I'll give that a try.

--
Grant Edwards grante Yow! .. I think I'd
at better go back to my DESK
visi.com and toy with a few common
MISAPPREHENSIONS...
Aug 2 '05 #9

"Gregory Piñero" <gr********@gmail.com> schrieb im Newsbeitrag
news:ma***************************************@pyt hon.org...
If you need something that works both on a frozen app as well as an
(unfrozen) python
script, you'd be better off using something like:
def getAppPrefix():
"""Return the location the app is running from
"""
isFrozen = False
try:
isFrozen = sys.frozen
except AttributeError:
pass
if isFrozen:
appPrefix = os.path.split(sys.executable)[0]
else:
appPrefix = os.path.split(os.path.abspath(sys.argv[0]))[0]
return appPrefix

Vincent,

This sounds interesting. A few questions for you:
Why don't I see sys.frozen in interpreter?
Does it only appear when it is frozen?


Yes. The sys.frozen attribute is added by py2exe.
What do you mean by frozen, how does python know?
Python doesn't know - it is just told so ;)
What does sys.executable do?
sys.executable gives you the path of the executing binary. Normally, this
will be something like
"c:\\python24\\python.exe" - since the interpreter is the executing binary.
Once you have frozen your python application, it will return the path to
your app.
--

Vincent

Thanks,

Greg

Aug 2 '05 #10

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...
20
by: Thomas Heller | last post by:
I'm currently working on a new version of py2exe, which will require Python 2.3 and later, because it uses the zipimport mechanism. Since py2exe is a distutils extension, and since C compilers...
2
by: Thomas Heller | last post by:
"Brad Clements" <bkc@murkworks.com> writes: > Once again I apologize for posting this py2exe question in the ctypes list. ;-) In the long run, this will be the wrong forum. I suggest...
5
by: Michael Peuser | last post by:
Hi, I should like to make a distribution (using Tkinter), with standard DLLs removed. pythonXX.dll is no problem. tcl und tk, which make the mass of mega bytes, cannot be removed because...
1
by: Funduk | last post by:
Hello, So I've been playing with Python and Pygame for a while and I decided I wanted to make a real executable so I could send that stuff over to my friends to show off my <sarcasm>maad...
0
by: David Vaughan | last post by:
py2exe and Pmw problem ---------------------- I was really surprised not to find some faq setting out what to do to get py2exe working for a program using Pmw. I'm haemorrhaging time here, and...
9
by: Isaac Rodriguez | last post by:
Hi, I am looking for feedback from people that has used or still uses Py2Exe. I love to program in python, and I would like to use it to write support tools for our development team, but I...
1
by: Dave Lim | last post by:
>On May 3, 1:29 pm, Dave Lim <diband... at yahoo.com> wrote: site:http://surguy.net/articles/speechrecognition.xml used out tried ? to protection aroundhttp://mail.yahoo.com I went and
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.