From: Mark H. <mha...@sk...> - 2012-02-01 23:51:02
|
The best I can suggest is that you experiment with a normal Python and use -v. Something like: set PYTHONPATH="C:\program Files\Gridzilla\bin\library.zip python -v -c "import gridder" And check out the verbose output - it should show you how it is attempting to look inside the .zip file, then you can apply that knowledge to your py2exe setup. Also note: > sys.path.append(r"C:|program Files\Gridzilla\bin\library.zip" Looks wrong - the "pipe" character | should be a backslash. Mark On 2/02/2012 9:23 AM, hari jayaram wrote: > Hello Mark and others, > I thought I had solved my problem yesterday by adding library.zip to > the python path in the child process. But it turns out that the only > reason it found the gridder module was because I had used the > Innosetup packager to supply the module gridder directory and also > added the exe directory (C:\Program Files\Gridzilla\bin ) to the > python path. > > If I just use library.zip the subprocess fails to find the gridder > module . In the above case where gridder module is present as a > separate directory\bin\gridder) , the subprocess fails to find > reportlab. > > So it seems like although my library.zip has all the requisite modules > - gridder , reportlab ..Adding it to the path in the script using line > below..does not result in them getting imported. > > sys.path.append(r"C:|program Files\Gridzilla\bin\library.zip" > > Could the fact that I am building on a 64 bit machine and running on a > 32 bit machine have something to do with it. > > I am using 32 bit python to do all the packaging. > > Still confused why my library.zip modules are not seen by the > subprocess script called from the py2exe program > > > Thanks for your help > > Hari > > > On Tue, Jan 31, 2012 at 8:13 PM, Mark Hammond<mha...@sk...> wrote: >> On 1/02/2012 12:02 PM, hari jayaram wrote: >>> >>> Thanks for your patience and help Mark. >>> >>> 1) Looking up the example from >>> http://www.py2exe.org/index.cgi/ListOfOptions >>> I got a correct setup file >>> >>> from distutils.core import setup >>> import py2exe >>> import gridder >>> setup(console=['gzilla.py'], options = { "py2exe" : {"includes" : >>> "gridder"}}) >>> >>> However I am still getting an "ImportError: no module named gridder" >>> though the module is now in the includes setting and it always was in >>> library.zip >> >> >> The problem is that a subprocess can't import that module, right? So all >> you need to do is arrange for library.zip to be in the PYTHONPATH for the >> sub-process - IIRC, you can explicitly specify an environment when creating >> a sub-process. >> >> The mention of "includes" was really just a distraction - that would allow >> you to arrange for gridder to be in library.zip even if that module wasn't >> directly imported by the "parent" process - but as you did add it to the >> parent process it isn't necessary. My other suggestion was to add the child >> processes main script to "includes" - that should avoid needing to reference >> gridder at all as it, and any other modules used by the child should then be >> automatically found and included without anything special being done in the >> parent. >> >> >>> >>> 2) I will follow the directions at >>> http://www.py2exe.org/index.cgi/WhereAmI and see how I can add either >>> library.zip or the gridder module itself to the PYTHONPATH >>> I am surprised that the exe cannot find the module even though it is >>> packaging it. Could it be that I have an empty__init__.py that is >>> screwing it up. >> >> >> Unless I'm misunderstanding your problem, the issue is that the child >> process isn't looking in library.zip at all, only the parent is - so the >> PYTHONPATH hack above should work. >> >> Note there is yet another alternative - have py2exe create an executable for >> your child process too (one setup.py can generate multiple targets). Then >> you change your subprocess invoking code to execute the generated exe - then >> it will automatically use library.zip and library.zip will automatically >> contain the union of all modules used by both executables. >> >> Hopefully I haven't misunderstood. >> >> Mark >> >> >>> >>> >>> Hoping I can figure this out. >>> Thanks >>> Hari >>> >>> >>> On Tue, Jan 31, 2012 at 7:39 PM, Mark Hammond<mha...@sk...> >>> wrote: >>>> >>>> On 1/02/2012 11:31 AM, hari jayaram wrote: >>>>> >>>>> >>>>> Thanks for your email Mark.. >>>>> >>>>> 1) How do I add the library.zip to the pythonpath. What is the path of >>>>> the >>>>> app? >>>>> Is it something like >>>>> >>>>> >>>>> sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)),"library.zip")) >>>> >>>> >>>> >>>> Easiest way is probably just to add it to the PYTHONPATH env var for the >>>> child. >>>> >>>> >>>>> >>>>> Or should I use something like here >>>>> http://www.py2exe.org/index.cgi/WhereAmI >>>>> >>>>> >>>>> 2) I couldnt find out how to add the includes directive in my >>>>> setup.py. Sorry I am confused since all the online examples seem to >>>>> have a different syntax >>>>>>> >>>>>>> >>>>>>> from distutils.core import setup >>>>>>> import py2exe >>>>>>> import gridder >>>>>>> setup(console=['gzilla.py'] ) >>>> >>>> >>>> >>>> The syntax is a little strained - something like: >>>> >>>>>>> setup(console=['gzilla.py'], >>>> >>>> options = {"py2exe": {"includes": "mod1, mod2"}}) >>>> >>>> inside that py2exe dict is where other py2exe options go - like >>>> "excludes", >>>> "dll_excludes" etc. >>>> >>>> HTH, >>>> >>>> Mark >>>> >>>> >>>> >>>>> >>>>> >>>>> Hari >>>>> >>>>> On Tue, Jan 31, 2012 at 7:08 PM, Mark Hammond<ski...@gm...> >>>>> wrote: >>>>>> >>>>>> >>>>>> On 1/02/2012 10:57 AM, hari jayaram wrote: >>>>>>> >>>>>>> >>>>>>> >>>>>>> Hello All, >>>>>>> >>>>>>> I have a wxpython GUI application that I am trying to make a >>>>>>> standalone exe executable for. >>>>>>> During user interaction the GUI creates a python script. >>>>>>> This script is then run using "subprocess.popen" with the arguments >>>>>>> ["python" ,"script.py"]. >>>>>>> >>>>>>> When I run the exe file created , using the wxpython GUI I >>>>>>> successfully create the script which is then run by clicking the run >>>>>>> script button in the GUI . >>>>>>> This calls the subprocess module . However at this stage I get a >>>>>>> >>>>>>> "ImportError no module named gridder" >>>>>>> >>>>>>> I have added a import gridder to the py2exe script and the wxpython >>>>>>> code . I even made sure I create some dummy objects with the gridder >>>>>>> module classes in my GUI code. >>>>>>> >>>>>>> When I check the library.zip , I see the gridder module stored there. >>>>>>> The build log also shows that py2exe is byte-compiling the gridder >>>>>>> module from site-packages/gridder directory. >>>>>>> >>>>>>> >>>>>>> Despite this does someone know why the subprocess script throws an >>>>>>> ImportError saying no module gridder. What can I get to have the >>>>>>> subprocess module bundled with the exe import and use the module >>>>>>> bundled in the library.zip >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> You probably just need to ensure library.zip (the file, not the >>>>>> directory >>>>>> holding the file) is on the PYTHONPATH in the child process. You could >>>>>> probably even add this module to the "includes" in your py2exe script >>>>>> and >>>>>> it >>>>>> should be scanned and further "sub-imports" will automagically be >>>>>> included. >>>>>> >>>>>> Mark >>>>>> >>>>>>> >>>>>>> >>>>>>> Thanks >>>>>>> >>>>>>> Hari >>>>>>> >>>>>>> ################### >>>>>>> my setup_file is simple: >>>>>>> ################### >>>>>>> >>>>>>> from distutils.core import setup >>>>>>> import py2exe >>>>>>> import gridder >>>>>>> setup(console=['gzilla.py']) >>>>>>> >>>>>>> >>>>>>> ############## >>>>>>> A sample script written by the application >>>>>>> ################ >>>>>>> >>>>>>> #!/usr/bin/python >>>>>>> import gridder >>>>>>> from gridder import masterplate,plate,component,buffercomponent >>>>>>> mp = masterplate.Masterplate(2000,96) >>>>>>> p11 = plate.Plate("A7","H7",mp) >>>>>>> p10 = plate.Plate("A6","H6",mp) >>>>>>> p13 = plate.Plate("A9","H9",mp) >>>>>>> p12 = plate.Plate("A8","H8",mp) >>>>>>> p15 = plate.Plate("A11","H11",mp) >>>>>>> p14 = plate.Plate("A10","H10",mp) >>>>>>> p17 = plate.Plate("A1","H12",mp) >>>>>>> p16 = plate.Plate("A12","H12",mp) >>>>>>> p1 = plate.Plate("A1","D6",mp) >>>>>>> p3 = plate.Plate("E1","H6",mp) >>>>>>> p2 = plate.Plate("A7","D12",mp) >>>>>>> p5 = plate.Plate("A1","H1",mp) >>>>>>> p4 = plate.Plate("E7","H12",mp) >>>>>>> p7 = plate.Plate("A3","H3",mp) >>>>>>> p6 = plate.Plate("A2","H2",mp) >>>>>>> p9 = plate.Plate("A5","H5",mp) >>>>>>> p8 = plate.Plate("A4","H4",mp) >>>>>>> c2 = component.Component("peg2kmme" , 50,10000000) >>>>>>> c3 = component.Component("peg5kmme" , 50,10000000) >>>>>>> c4 = component.Component("peg2k" , 50,10000000) >>>>>>> c5 = component.Component("peg3350" , 50,10000000) >>>>>>> c6 = component.Component("peg4k" , 50,10000000) >>>>>>> c7 = component.Component("peg8k" , 50,10000000) >>>>>>> c8 = component.Component("glycerol" , 50,10000000) >>>>>>> c9 = component.Component("hepesph7p5" , 1,10000000) >>>>>>> c10 = component.Component("amsulfate4m" , 4,10000000) >>>>>>> p17.push_component_uniform_to_masterplate(c9,0.1) >>>>>>> p7.gradientlist_along_y(c4,[30,27.5,25,22.5,30,27.5,25,22.5]) >>>>>>> p8.gradientlist_along_y(c5,[30,27.5,25,22.5,30,27.5,25,22.5]) >>>>>>> p9.gradientlist_along_y(c6,[30,27.5,25,22.5,30,27.5,25,22.5]) >>>>>>> p10.gradientlist_along_y(c7,[30,27.5,25,22.5,30,27.5,25,22.5]) >>>>>>> p11.gradientlist_along_y(c2,[30,27.5,25,22.5,30,27.5,25,22.5]) >>>>>>> p12.gradientlist_along_y(c3,[30,27.5,25,22.5,30,27.5,25,22.5]) >>>>>>> p13.gradientlist_along_y(c4,[30,27.5,25,22.5,30,27.5,25,22.5]) >>>>>>> p14.gradientlist_along_y(c5,[30,27.5,25,22.5,30,27.5,25,22.5]) >>>>>>> p15.gradientlist_along_y(c6,[30,27.5,25,22.5,30,27.5,25,22.5]) >>>>>>> p16.gradientlist_along_y(c7,[30,27.5,25,22.5,30,27.5,25,22.5]) >>>>>>> p2.push_component_uniform_to_masterplate(c8,7.5) >>>>>>> p17.push_component_rowlist(c8,12.5,["E"]) >>>>>>> p17.push_component_rowlist(c8,15,["F","G","H"]) >>>>>>> p17.push_component_rowlist(c10,0.2,["A","B","C","D"]) >>>>>>> p3.push_component_uniform_to_masterplate(c10,0.2) >>>>>>> p4.push_component_uniform_to_masterplate(c10,0.1) >>>>>>> p5.gradientlist_along_y(c2,[30,27.5,25,22.5,30,27.5,25,22.5]) >>>>>>> p6.gradientlist_along_y(c3,[30,27.5,25,22.5,30,27.5,25,22.5]) >>>>>>> water = component.Component("100.00 % Water",100,100000) >>>>>>> p17.fill_water(water) >>>>>>> p7.fill_water(water) >>>>>>> p8.fill_water(water) >>>>>>> p9.fill_water(water) >>>>>>> p10.fill_water(water) >>>>>>> p11.fill_water(water) >>>>>>> p12.fill_water(water) >>>>>>> p13.fill_water(water) >>>>>>> p14.fill_water(water) >>>>>>> p15.fill_water(water) >>>>>>> p16.fill_water(water) >>>>>>> p2.fill_water(water) >>>>>>> p3.fill_water(water) >>>>>>> p4.fill_water(water) >>>>>>> p5.fill_water(water) >>>>>>> p6.fill_water(water) >>>>>>> mp.printwellinfo() >>>>>>> >>>>>>> mp.makefileforformulatrix(r"C:\Users\hari.jayaram\Desktop\test.dl.txt") >>>>>>> mp.writepdf(r"C:\Users\hari.jayaram\Desktop\test") >>>>>>> >>>>>>> >>>>>>> >>>>>>> mp.makefileforhamilton(r"C:\Users\hari.jayaram\Desktop\test-hamilton.csv",1) >>>>>>> >>>>>>> ############## >>>>>>> Code that calls the script once it is written >>>>>>> ############### >>>>>>> os.chmod((os.path.join(self.GetParent().dirtowriteto,"%s_scr.py" % >>>>>>> >>>>>>> >>>>>>> >>>>>>> str(self.GetParent().FindWindowByName("mpanel").file_name_text.GetValue()))),0755) >>>>>>> subp_status = >>>>>>> >>>>>>> >>>>>>> subprocess.Popen(["python",os.path.join(self.GetParent().dirtowriteto,"%s_scr.py" >>>>>>> % >>>>>>> >>>>>>> >>>>>>> str(self.GetParent().FindWindowByName("mpanel").file_name_text.GetValue()))],shell=False,stderr=subprocess.PIPE,stdout=subprocess.PIPE) >>>>>>> mystdout,mystderr = subp_status.communicate() >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> ------------------------------------------------------------------------------ >>>>>>> Keep Your Developer Skills Current with LearnDevNow! >>>>>>> The most comprehensive online learning library for Microsoft >>>>>>> developers >>>>>>> is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, >>>>>>> MVC3, >>>>>>> Metro Style Apps, more. Free future releases when you subscribe now! >>>>>>> http://p.sf.net/sfu/learndevnow-d2d >>>>>>> _______________________________________________ >>>>>>> Py2exe-users mailing list >>>>>>> Py2...@li... >>>>>>> https://lists.sourceforge.net/lists/listinfo/py2exe-users >>>>>> >>>>>> >>>>>> >>>>>> >>>> >> |