compiling to myProgram.exe from myProgram.pyw

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • freddypyther
    New Member
    • May 2007
    • 10

    compiling to myProgram.exe from myProgram.pyw

    Hi!!!

    I need some help:

    I have a program: myProgram.pyw, and I want it like myProgram.exe so anyone can run it in a windows xp without installing nothing.

    I've read how py2exe works and I undersand it when is a simple program.

    myProgram.pyw uses ImageGrab module and pyHook module.

    How I can create myProgram.exe that "include" that modules and run with no problems¿??

    Thanks!!!!
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by freddypyther
    Hi!!!

    I need some help:

    I have a program: myProgram.pyw, and I want it like myProgram.exe so anyone can run it in a windows xp without installing nothing.

    I've read how py2exe works and I undersand it when is a simple program.

    myProgram.pyw uses ImageGrab module and pyHook module.

    How I can create myProgram.exe that "include" that modules and run with no problems¿??

    Thanks!!!!
    I've been working with Py2Exe and have learned some tricks. I have posted here (which is NOT for Q&A) and other placed also in the Articles Section.

    Do some work on you setup file and post back IN THIS THREAD.

    Thanks for joining.

    Comment

    • freddypyther
      New Member
      • May 2007
      • 10

      #3
      Originally posted by bartonc
      I've been working with Py2Exe and have learned some tricks. I have posted here (which is NOT for Q&A) and other placed also in the Articles Section.

      Do some work on you setup file and post back IN THIS THREAD.

      Thanks for joining.
      Hi! sorry for PM you, I didn't know about the rules.


      Here I have my simple program: a screen shot taker:
      [CODE=python]
      import ImageGrab,pytho ncom,pyHook,os
      from datetime import *
      def OnKeyboardEvent (event):
      if(event.Key==" F7"):
      #catching the f7 event
      s=getDateInStri ng()
      aux=r"C:\\Scree nShots\\ss"
      path=aux+s+".jp g"
      print path
      img = ImageGrab.grab( )
      img.save(path)
      return True
      def getDateInString ():
      #tunning the path
      s=str(datetime. today()).split( ' ')
      return s[0]+'-'+s[1].replace(':','-').split('.')[0]
      # if dont exist, create directory where all ss will be saved
      if(os.access("C :\\ScreenShots" ,os.F_OK)==Fals e):
      os.mkdir("C:\\S creenShots")
      # create a hook manager
      hm = pyHook.HookMana ger()
      # watch for all mouse events
      hm.KeyDown = OnKeyboardEvent
      # set the hook
      hm.HookKeyboard ()
      # wait forever
      pythoncom.PumpM essages()
      [/CODE]



      it's named sstaker.pyw.

      the ImageGrab module is Python Imaging Library 1.1.6 for Python 2.5 (Windows only) on http://www.pythonware.com/products/pil/index.htm

      the pyHook module is http://sourceforge.net/project/downl...5.exe&37280531
      for windows too.

      os and datetime comes with python.

      If only I could get a sstaker.exe which I can pass anyone with windows xp without that person installs nothing previously.
      Last edited by bartonc; May 23 '07, 05:12 PM. Reason: added [code][/code] tags

      Comment

      • freddypyther
        New Member
        • May 2007
        • 10

        #4
        oh :( At least tell me if it is possible to do, because I'm trying to get it for more than one month asking in a lot of forums and reading tutorials...

        Comment

        • bartonc
          Recognized Expert Expert
          • Sep 2006
          • 6478

          #5
          Originally posted by freddypyther
          oh :( At least tell me if it is possible to do, because I'm trying to get it for more than one month asking in a lot of forums and reading tutorials...
          Sorry, Freddy. My connections been wonky all day. It is possible and probably even easy. Give me a little bit to get to this.

          Thanks.

          Comment

          • bartonc
            Recognized Expert Expert
            • Sep 2006
            • 6478

            #6
            Originally posted by bartonc
            Sorry, Freddy. My connections been wonky all day. It is possible and probably even easy. Give me a little bit to get to this.

            Thanks.
            Re-subscribing and bumping...

            Comment

            • bartonc
              Recognized Expert Expert
              • Sep 2006
              • 6478

              #7
              Originally posted by freddypyther
              Hi! sorry for PM you, I didn't know about the rules.


              Here I have my simple program: a screen shot taker:
              [CODE=python]
              import ImageGrab,pytho ncom,pyHook,os
              from datetime import *
              def OnKeyboardEvent (event):
              if(event.Key==" F7"):
              #catching the f7 event
              s=getDateInStri ng()
              aux=r"C:\\Scree nShots\\ss"
              path=aux+s+".jp g"
              print path
              img = ImageGrab.grab( )
              img.save(path)
              return True
              def getDateInString ():
              #tunning the path
              s=str(datetime. today()).split( ' ')
              return s[0]+'-'+s[1].replace(':','-').split('.')[0]
              # if dont exist, create directory where all ss will be saved
              if(os.access("C :\\ScreenShots" ,os.F_OK)==Fals e):
              os.mkdir("C:\\S creenShots")
              # create a hook manager
              hm = pyHook.HookMana ger()
              # watch for all mouse events
              hm.KeyDown = OnKeyboardEvent
              # set the hook
              hm.HookKeyboard ()
              # wait forever
              pythoncom.PumpM essages()
              [/CODE]



              it's named sstaker.pyw.

              the ImageGrab module is Python Imaging Library 1.1.6 for Python 2.5 (Windows only) on http://www.pythonware.com/products/pil/index.htm

              the pyHook module is http://sourceforge.net/project/downl...5.exe&37280531
              for windows too.

              os and datetime comes with python.

              If only I could get a sstaker.exe which I can pass anyone with windows xp without that person installs nothing previously.
              Your post is very complete and allowed me to get you program up and running in no time. Your program is perhaps a little too simple (no way to kill it other than T.M.) Seems like it needs some work to make sure that it doesn't steal F7 from any other running programs, also. I'll run it through py2exe, though (but don't have a lot of time at the moment).

              I am curious for the need for such a program when windows will capture the screen to the clipboard which give users a chance to select format and directory (features that would be a great addition to your program).

              Comment

              • freddypyther
                New Member
                • May 2007
                • 10

                #8
                Originally posted by bartonc
                Your post is very complete and allowed me to get you program up and running in no time. Your program is perhaps a little too simple (no way to kill it other than T.M.) Seems like it needs some work to make sure that it doesn't steal F7 from any other running programs, also. I'll run it through py2exe, though (but don't have a lot of time at the moment).

                I am curious for the need for such a program when windows will capture the screen to the clipboard which give users a chance to select format and directory (features that would be a great addition to your program).

                Hi, you are right, my program is not very useful, but is the first program I do that interaction with the operating system, and I wanted that do a simple task like that.

                The main utility of this little program is that saves the picture with the name year-month-day-hour-min-sec in jpg in a directory every time the user press F7. I know the user could do that with the Impr pant key but he would have to open Paint and paste and save it on jpg and put a name and select the directory (maybe there is another form, will be great if you could tell me about). And the idea is, that if I'm playing a game (not counter strike or so that have a lot of video recorders, a simple and not famous game) I can be playing and taking the screen shots just pressing F7 the times I want.

                Anyway, will be great if you could help me improving my little program (I've been thinking in a system tray icon or so too) but will be great if I knew how to make an exe of my programs because most people wont install python and all the modules just for see how my little program works.

                Thank you very much!

                Comment

                • bartonc
                  Recognized Expert Expert
                  • Sep 2006
                  • 6478

                  #9
                  Originally posted by freddypyther
                  Hi, you are right, my program is not very useful, but is the first program I do that interaction with the operating system, and I wanted that do a simple task like that.

                  The main utility of this little program is that saves the picture with the name year-month-day-hour-min-sec in jpg in a directory every time the user press F7. I know the user could do that with the Impr pant key but he would have to open Paint and paste and save it on jpg and put a name and select the directory (maybe there is another form, will be great if you could tell me about). And the idea is, that if I'm playing a game (not counter strike or so that have a lot of video recorders, a simple and not famous game) I can be playing and taking the screen shots just pressing F7 the times I want.

                  Anyway, will be great if you could help me improving my little program (I've been thinking in a system tray icon or so too) but will be great if I knew how to make an exe of my programs because most people wont install python and all the modules just for see how my little program works.

                  Thank you very much!
                  Very well said, Freddy. I'll make some time this weekend for the py2exe part (I need the practice anyway). Then we can work on a more freindly "environmen t" for your utility to live in.

                  Comment

                  • freddypyther
                    New Member
                    • May 2007
                    • 10

                    #10
                    Originally posted by bartonc
                    Very well said, Freddy. I'll make some time this weekend for the py2exe part (I need the practice anyway). Then we can work on a more freindly "environmen t" for your utility to live in.

                    Thanks! man you rock!!

                    Comment

                    • bartonc
                      Recognized Expert Expert
                      • Sep 2006
                      • 6478

                      #11
                      Originally posted by freddypyther
                      Thanks! man you rock!!
                      Here's one thing that I did to make your program more managable:
                      Change the extention to .py so that the python stdout/stderr window comes up when you double-click the file (if you are still needing the command-line, we can adjust your system). That way, at least the program can be killed without using Task Manager.

                      Comment

                      • freddypyther
                        New Member
                        • May 2007
                        • 10

                        #12
                        Originally posted by bartonc
                        Here's one thing that I did to make your program more managable:
                        Change the extention to .py so that the python stdout/stderr window comes up when you double-click the file (if you are still needing the command-line, we can adjust your system). That way, at least the program can be killed without using Task Manager.
                        Thanks, that was how I had it before changing the extension to .pyw. I like that a program runs without the console behind him. I was thinking and googleing for some icon in the system tray (down right on windows xp, where emule, messenger are) seems like PyQt can do it. Do you know something about?

                        Will be so well-looked an icon in the system try with the right-mouse button opcion "close" or something like that.

                        What do you think? Thanks!

                        Comment

                        • bartonc
                          Recognized Expert Expert
                          • Sep 2006
                          • 6478

                          #13
                          Originally posted by freddypyther
                          Thanks, that was how I had it before changing the extension to .pyw. I like that a program runs without the console behind him. I was thinking and googleing for some icon in the system tray (down right on windows xp, where emule, messenger are) seems like PyQt can do it. Do you know something about?

                          Will be so well-looked an icon in the system try with the right-mouse button opcion "close" or something like that.

                          What do you think? Thanks!
                          My GUI toolkit is wxPython. It can do system tray icons, but I haven't tried it yet. I really like the idea, though.

                          Comment

                          • freddypyther
                            New Member
                            • May 2007
                            • 10

                            #14
                            Maybe if I make a package with the classes that are involved in my little program (I'm thinking like a .jar in java, I don't know how it works in python) would be easier get my "sstaker.ex e"?

                            Comment

                            • bartonc
                              Recognized Expert Expert
                              • Sep 2006
                              • 6478

                              #15
                              Originally posted by freddypyther
                              Maybe if I make a package with the classes that are involved in my little program (I'm thinking like a .jar in java, I don't know how it works in python) would be easier get my "sstaker.ex e"?
                              Well, Freddy, the ball's in your court now. I've worked on this for as long as I can. Sorry for screwing up the names. This setup script (when run in the same directory as you program will compile your sstaker.exe (I called it ImageGrabber) on line 20. For some reason (maybe this won't work at all) the events are not being registered with pyHook. The pumpmessages() seems to be working since the program doesn't exit immediately. I think that if you track down the "missing modules" error by playing with "includes" and "excludes" lists, you may have success. Have fun![CODE=python]# Py2Exe version 6.3 setup file for wxPython GUI programs.
                              # Creates a single exe file.
                              # It's easiest to add this wxPython2Exe.py file into the same
                              # folder with the source file and an optional iconfile like "icon.ico"
                              # (if you add your own icon file, remove the comment in front of icon_resources) .
                              # Simply change the filename to whatever you called your source file.
                              # Optionally edit the version info and add the name of your icon file.
                              # Now run wxPython2Exe.py ...
                              # Two subfolders will be created called build and dist.
                              # The dist folder contains your .exe file, MSVCR71.dll and w9xpopen.exe
                              # Your .exe file contains your code, all neded modules and the Python interpreter.
                              # The MSVCR71.dll can be distributed, but is often already in the system32 folder.

                              from distutils.core import setup
                              import py2exe
                              import sys


                              # enter the filename of your wxPython code file to compile ...
                              filename = "ImageGrabber.p y"

                              # ... this creates the filename of your .exe file in the dist folder
                              if filename.endswi th(".py"):
                              distribution = filename[:-3]
                              elif filename.endswi th(".pyw"):
                              distribution = filename[:-4]


                              # if run without args, build executables in quiet mode
                              if len(sys.argv) == 1:
                              sys.argv.append ("py2exe")
                              sys.argv.append ("-q")

                              class Target:
                              def __init__(self, **kw):
                              self.__dict__.u pdate(kw)
                              # for the versioninfo resources, edit to your needs
                              self.version = "0.0.1"
                              self.company_na me = "freddypyth er"
                              self.copyright = "no copyright"
                              self.name = "Background Image Grabber"

                              ############### ############### ############### ############### ####
                              # The manifest will be inserted as resource into your .exe. This
                              # gives the controls the Windows XP appearance (if run on XP ;-)
                              #
                              # Another option would be to store it in a file named
                              # test_wx.exe.man ifest, and copy it with the data_files option into
                              # the dist-dir.
                              #
                              manifest_templa te = '''
                              <?xml version="1.0" encoding="UTF-8" standalone="yes "?>
                              <assembly xmlns="urn:sche mas-microsoft-com:asm.v1" manifestVersion ="1.0">
                              <assemblyIdenti ty
                              version="5.0.0. 0"
                              processorArchit ecture="x86"
                              name="%(prog)s"
                              type="win32"
                              />
                              <description>%( prog)s Program</description>
                              <dependency>
                              <dependentAssem bly>
                              <assemblyIdenti ty
                              type="win32"
                              name="Microsoft .Windows.Common-Controls"
                              version="6.0.0. 0"
                              processorArchit ecture="X86"
                              publicKeyToken= "6595b64144ccf1 df"
                              language="*"
                              />
                              </dependentAssemb ly>
                              </dependency>
                              </assembly>
                              '''

                              RT_MANIFEST = 24

                              # description is the versioninfo resource
                              # script is the wxPython code file
                              # manifest_templa te is the above XML code
                              # distribution will be the exe filename
                              # icon_resource is optional, remove any comment and give it an iconfile you have
                              # otherwise a default icon is used
                              # dest_base will be the exe filename
                              test_grabber = Target(
                              description = "A non-GUI app",
                              script = filename,
                              other_resources = [(RT_MANIFEST, 1, manifest_templa te % dict(prog=distr ibution))],
                              #icon_resources = [(1, "icon.ico")],
                              dest_base = distribution)

                              ############### ############### ############### ############### ####
                              excludes = ["pywin.debugger ", "pywin.debugger .dbgcon",
                              "pywin.dialogs" , "pywin.dialogs. list",
                              "Tkconstants"," Tkinter","tcl",
                              ] # "pywin",
                              includes = ['PIL._imaging', 'pyHook.cpyHook ']

                              setup(
                              # Need a console to be able to kill this non-GUI deamon #
                              ## windows = [test_grabber,],
                              ## console = [filename],
                              console = [test_grabber],
                              options = {"py2exe": {"compressed ": 1,
                              "optimize": 2,
                              "ascii": 1,
                              "bundle_fil es": 1,
                              "packages":["PIL", "pyHook",],
                              "excludes":excl udes,
                              "includes":incl udes}}, #
                              zipfile = None,
                              )
                              [/CODE]

                              Comment

                              Working...