[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pythonmac-sig
Subject:    Re: Re: [Pythonmac-SIG] Re: Newbie path problem
From:       Christer Fernstrom <christer () fernstromOnThe ! net>
Date:       2004-02-27 20:33:20
Message-ID: 2E5FF666-6964-11D8-BEDE-003065EF5D8A () fernstromOnThe ! net
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


-- christer

On 27 févr. 04, at 11:09, Jack Jansen wrote:

>
> On 26-feb-04, at 16:12, Christer Fernstrom wrote:
>
>>>> Sorry, I'll try to make it clearer. The first module, Module-A, is 
>>>> the main program module. It imports Module-B, which resides in the 
>>>> same directory as Module-A. This directory, Directory-D, is not on 
>>>> the PYTHONPATH. Using terminal, and positioned in any directory, I 
>>>> can successfully invoke Module-A:
>>>>  % python Directory-D/Module-A.py <paramters>
>>>> Printing out the value of sys.path tells me that its first element 
>>>> is "Directory-D", which explains why the import of Module-B works 
>>>> fine.
>>>>
>>>> The problem occurs when I transform Module-A to an applet, using 
>>>> BuildApplet. The import now fails, and looking at the Console 
>>>> window I can see that sys.path now prints with a different value, 
>>>> and in particular its first two elements are identical. They 
>>>> contain "Directory-D/Module-A.app/Contents/Resources". It does not 
>>>> contain Directory-D, which explains why the import fails.
>>>>
>>>> I could of course work around this in my code, but it doesn't seem 
>>>> very clean to do it that way.
>>>
>>> Have you tried copying Module-B into Module-A.app/Contents/Resources 
>>> ? Everything you need either needs to be findable from sys.path, or 
>>> you will have yourself a location-dependent app (i.e. if you moved 
>>> Module-A.app to any other location then it would no longer work).
>>>
>>> -bob
>>>
>> I assume it would work, but then this would depend on the fact that I 
>> run Module-A as an applet and not a script. In my humble opinion, it 
>> is the AppletBuilder's responsibility to initialise sys.path to 
>> contain Module-A's source directory.
>
> You're trying to do something BuildApplet wasn't intended for. 
> BuildApplet takes a script that is self-contained (except for 
> dependencies on the standard Python library) and packages it as an 
> application. You can now move the resulting applet around on your 
> disk, and even copy it to other machines with the same Python 
> installation. Keeping a reference to the source directory isn't a good 
> idea: it would break copying the applet to a different machine.
>
> For more control over what exactly goes into the applet you want to 
> use bundlebuilder. Unfortunately there isn't a good GUI for 
> bundlebuilder just yet, so you have to use the command line tool.
>
> Actually, BuildApplet is a remnant of MacPython-OS9, which had an 
> all-singing-all-dancing application builder too: BuildApplication. 
> BuildApplet was converted to OSX by using bundlebuilder under the 
> hood, but BuildApplication wasn't. For 2.4 we should come up with a 
> GUI tool that does both of these, and preferably the various 
> intermediate possibilities as well.
> --
> Jack Jansen, <Jack.Jansen@cwi.nl>, http://www.cwi.nl/~jack
> If I can't dance I don't want to be part of your revolution -- Emma 
> Goldman
>

Makes sense. Thanks for your help!
-- christer


<smaller>-- christer

</smaller>

On 27 f=E9vr. 04, at 11:09, Jack Jansen wrote:


<excerpt>

On 26-feb-04, at 16:12, Christer Fernstrom wrote:


<excerpt><excerpt><excerpt>Sorry, I'll try to make it clearer. The
first module, Module-A, is the main program module. It imports
Module-B, which resides in the same directory as Module-A. This
directory, Directory-D, is not on the PYTHONPATH. Using terminal, and
positioned in any directory, I can successfully invoke Module-A:

 % python Directory-D/Module-A.py <<paramters>

Printing out the value of sys.path tells me that its first element is
"Directory-D", which explains why the import of Module-B works fine.


The problem occurs when I transform Module-A to an applet, using
BuildApplet. The import now fails, and looking at the Console window I
can see that sys.path now prints with a different value, and in
particular its first two elements are identical. They contain
"Directory-D/Module-A.app/Contents/Resources". It does not contain
Directory-D, which explains why the import fails.


I could of course work around this in my code, but it doesn't seem
very clean to do it that way.

</excerpt>

Have you tried copying Module-B into Module-A.app/Contents/Resources ?
Everything you need either needs to be findable from sys.path, or you
will have yourself a location-dependent app (i.e. if you moved
Module-A.app to any other location then it would no longer work).


-bob


</excerpt>I assume it would work, but then this would depend on the
fact that I run Module-A as an applet and not a script. In my humble
opinion, it is the AppletBuilder's responsibility to initialise
sys.path to contain Module-A's source directory.

</excerpt>

You're trying to do something BuildApplet wasn't intended for.
BuildApplet takes a script that is self-contained (except for
dependencies on the standard Python library) and packages it as an
application. You can now move the resulting applet around on your
disk, and even copy it to other machines with the same Python
installation. Keeping a reference to the source directory isn't a good
idea: it would break copying the applet to a different machine.


For more control over what exactly goes into the applet you want to
use bundlebuilder. Unfortunately there isn't a good GUI for
bundlebuilder just yet, so you have to use the command line tool.


Actually, BuildApplet is a remnant of MacPython-OS9, which had an
all-singing-all-dancing application builder too: BuildApplication.
BuildApplet was converted to OSX by using bundlebuilder under the
hood, but BuildApplication wasn't. For 2.4 we should come up with a
GUI tool that does both of these, and preferably the various
intermediate possibilities as well.

--

Jack Jansen, <<Jack.Jansen@cwi.nl>, http://www.cwi.nl/~jack

If I can't dance I don't want to be part of your revolution -- Emma
Goldman


</excerpt>

Makes sense. Thanks for your help!

-- christer



_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic