Re: py2exe windows apps path question

2005-08-02 Thread vincent wehren

Grant Edwards [EMAIL PROTECTED] schrieb im Newsbeitrag 
news:[EMAIL PROTECTED]
|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.comand toy with a few 
common
|   MISAPPREHENSIONS... 


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


Re: py2exe windows apps path question

2005-08-02 Thread Grant Edwards
On 2005-08-02, vincent wehren [EMAIL PROTECTED] wrote:

 Grant Edwards [EMAIL PROTECTED] schrieb im Newsbeitrag 
 news:[EMAIL PROTECTED]
|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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: py2exe windows apps path question

2005-08-02 Thread vincent wehren
Gregory Piñero [EMAIL PROTECTED] schrieb im Newsbeitrag 
news:[EMAIL PROTECTED]

|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


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

Re: py2exe windows apps path question

2005-08-02 Thread vincent wehren
Grant Edwards [EMAIL PROTECTED] schrieb im Newsbeitrag 
news:[EMAIL PROTECTED]
| On 2005-08-02, vincent wehren [EMAIL PROTECTED] wrote:
| 
|  Grant Edwards [EMAIL PROTECTED] schrieb im Newsbeitrag
|  news:[EMAIL PROTECTED]
| |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 


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


Re: py2exe windows apps path question

2005-08-02 Thread Gregory Piñero
 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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: py2exe windows apps path question

2005-08-02 Thread Grant Edwards
On 2005-08-02, vincent wehren [EMAIL PROTECTED] 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.comand toy with a few common
   MISAPPREHENSIONS...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: py2exe windows apps path question

2005-08-02 Thread vincent wehren

Gregory Piñero [EMAIL PROTECTED] schrieb im Newsbeitrag 
news:[EMAIL PROTECTED]
 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 


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