Re: [Pgu-devel] pgu and py2exe -- problem solved
Status: Beta
Brought to you by:
philhassey
From: Glenn L. <gle...@ma...> - 2007-05-29 16:09:14
|
Phil, Tried that and couldn't find the site, either as svn or http. Anyway, I finally decided that my only alternative was to spend a few hours running experiments. You gave me enough information so that I knew what files I needed (the default folder), and I figured that I could find the right location for these files by trial and error. I finally got it to work. The correct command is shutil.copytree('data/themes/default','dist/default') This is anything but obvious. I can't believe that I am the only person who has ever run into this problem, nor can I believe that I'm the only person with this problem who couldn't just figure it out in a few minutes. Future pgu users might appreciate having a note of this problem put on the pgu web page. Something like this: "Q: I've got a program that uses python, pygame, and pgu, and I want to use py2exe to make an executable. Everything seems to work until I try to run the executable, at which point I get an error about some problem with app.pyc and themes.pyc. What do I do to fix this? A: Make sure that the data folder from the pgu distribution is in the main python directory that houses the program file and the setup file. You need to make two changes to setup.py. First, add the line import shutil in the beginning portion, if it isn't already there. This command loads a utility that copies files. Second, at the bottom of the file, add the line shutil.copytree('data/themes/default','dist/default') This command copies all of the files in the data/themes/default directory tree of the pgu distribution into a new folder called default that is created in the dist folder along with the executable and other files. This command only works if you don't already have a dist/default folder; delete an old version of this folder before running setup.py. " Now that I've got my project working, I want to say that I'm very pleased with my experience of programming with python, pygame, and pgu. The pygame documentation is first-rate. While I couldn't find everything I wanted in the pgu documentation, the Pitcher's Duel example taught me what I needed to know about using pgu to make a gui with a variety of widgets. As a professional mathematician, I'm great at programming a simulation based on scientific assumptions, but I lack the programming skills to write professional code in javascript. A simulation written in software generally unknown outside of mathematics departments doesn't have adequate availability for full utilization. Now any user can run my code simply by downloading a zip file, unpacking the contents, and double-clicking the executable. When I have more ideas for college-level educational tools, I'll definitely use the same programming environment. Best wishes, Glenn Ledder U of Nebraska-Lincoln _____ From: pgu...@li... [mailto:pgu...@li...] On Behalf Of Phil Hassey Sent: Sunday, May 27, 2007 6:08 PM To: pgu...@li... Subject: Re: [Pgu-devel] pgu and py2exe Glenn, I'm having a tough time following all that ... You might want to check out svn://www.imitationpickles.org/pyweek4/trunk -- it includes a setup.py script that uses py2exe without any trouble. It manages to copy the gui data as well. Thanks! Phil Glenn Ledder <gle...@ma...> wrote: Phil, I don't understand your reply. Do you mean that the C:/Python25/data/themes folder, which came from the pgu package but is not in a folder named "pgu", needs to be present as C:/Python25/dist/pgu/data/themes? This seems weird, but I tried it anyway. I got the same error message. Do you mean that the data/themes folder included as part of the pgu package needs to be present as /dist/data/themes? The command shutil.copytree('data','dist/data') seems to have done that just fine. In short, test.py runs fine from C:\Python25 with your pgu stuff in C:\Python25\pgu and C:\Python25\data, but test.exe does not run from C:\Python25\dist with exactly the same pgu stuff in C:\Python25\dist\pgu and C:\Python25\dist\data. It's weird that nobody else seems to have had a problem using pgu with py2exe. There are lots of reports on the web of people having trouble with the fonts in pygame. Surely some people have used pgu with py2exe and yet there are no reports of problems. Glenn In a message dated 5/26/2007 11:18:45 AM Central Daylight Time, phi...@ya... writes: Glenn, You need to include (from pgu) the data/themes folder. Hope that helps! Phil Glenn Ledder wrote: After a necessary break, I'm back to finishing my software project. I'm still stuck on getting py2exe and pgu to work together. I put together a test case. I'll be grateful for any help! I probably have made some obvious mistake, but I just can't see it. Here is the code for the file test.py. ################################################ import pygame, sys from pygame.locals import * from pgu import text, gui pygame.init() white = (255, 255, 255) width = 200 height = 100 def finish(): sys.exit() # create the display screen screen = pygame.display.set_mode((200,100)) screen.fill(white) # create GUI object pgu = gui.App() IO = gui.Container(width=200,height=100) # define widget quitt = gui.Button("QUIT") quitt.connect(gui.CLICK, finish) IO.add(quitt,width/2-25,height/2-10) # show the display pgu.init(IO) pgu.paint(screen) pygame.display.update() # handle input events while True: for event in pygame.event.get(): if event.type == QUIT: sys.exit() elif event.type == KEYDOWN and event.key == K_ESCAPE: sys.exit() pgu.event(event) pgu.paint(screen) pygame.display.update() ################################################ When I double-click on test.py, the file runs correctly. Here is the code for setup.py. ################################################ # setup.py from distutils.core import setup from pgu import text, gui import py2exe, pygame, sys import shutil setup(windows=["test.py"]) shutil.copytree('data','dist/data') shutil.copytree('pgu','dist/pgu') ################################################ I got a command window and set it to the Python25 directory. Then I entered python setup.py py2exe This resulted in a huge output dump in the command window. There are a lot of lines like skipping byte-compilation of C:\Python25\pgu\gui\theme.py to pgu\gui\theme.pyc Then there are a lot of lines about copying stuff from the pygame folder, followed by the usual stuff that certain modules appear to be missing and a list of dll files in system32. I don't think any of this stuff is important because py2exe works fine when test.py does not use pgu. After this operation, the new C:\Python25\dist\ folder contains subfolders called data and pgu, and these appear to be identical to the data and pgu folders in C:\Python25\. Finally, when I double-click on C:\Python25\dist\test.exe, I get the following log: C:\Python25\dist\library.zip\pgu\gui\theme.py:72: DeprecationWarning: raising a string exception is deprecated Traceback (most recent call last): File "test.py", line 18, in File "pgu\gui\app.pyc", line 42, in __init__ File "pgu\gui\theme.pyc", line 41, in __init__ File "pgu\gui\theme.pyc", line 49, in _preload File "pgu\gui\theme.pyc", line 72, in _load could not find theme default I checked the directories and there are files C:\Python25\dist\pgu\gui\theme.pyc and C:\Python25\dist\library.zip\pgu\gui\theme.pyc, although there is no C:\Python25\dist\library.zip\pgu\gui\theme.py. One last bit of information. When I double-click on test.exe, I actually do get a pygame window of the correct size; however, the window is black and there is no "Quit" button. Can anyone diagnose the problem for me? Is there something wrong with the way I use pgu commands in test.py? Thanks! Glenn ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Pgu-devel mailing list Pgu...@li... https://lists.sourceforge.net/lists/listinfo/pgu-devel _____ Got a little couch potato? Check out fun summer <http://us.rd.yahoo.com/evt=48248/*http://search.yahoo.com/search?fr=oni_on_ mail&p=summer+activities+for+kids&cs=bz> activities for kids. |