473,320 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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!!!!
May 22 '07 #1
20 4556
bartonc
6,596 Expert 4TB
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.
May 22 '07 #2
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:
Expand|Select|Wrap|Line Numbers
  1. import ImageGrab,pythoncom,pyHook,os
  2. from datetime import *
  3. def OnKeyboardEvent(event):
  4.    if(event.Key=="F7"):
  5.       #catching the f7 event
  6.       s=getDateInString()
  7.       aux=r"C:\\ScreenShots\\ss"
  8.       path=aux+s+".jpg"
  9.       print path
  10.       img = ImageGrab.grab()
  11.       img.save(path)
  12.    return True
  13. def getDateInString():
  14.    #tunning the path
  15.    s=str(datetime.today()).split(' ')
  16.    return s[0]+'-'+s[1].replace(':','-').split('.')[0]
  17. # if dont exist, create directory where all ss will be saved
  18. if(os.access("C:\\ScreenShots",os.F_OK)==False):
  19.    os.mkdir("C:\\ScreenShots")
  20. # create a hook manager
  21. hm = pyHook.HookManager()
  22. # watch for all mouse events
  23. hm.KeyDown = OnKeyboardEvent
  24. # set the hook
  25. hm.HookKeyboard()
  26. # wait forever
  27. pythoncom.PumpMessages()
  28.  


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.
May 23 '07 #3
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...
May 24 '07 #4
bartonc
6,596 Expert 4TB
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.
May 24 '07 #5
bartonc
6,596 Expert 4TB
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...
May 24 '07 #6
bartonc
6,596 Expert 4TB
Hi! sorry for PM you, I didn't know about the rules.


Here I have my simple program: a screen shot taker:
Expand|Select|Wrap|Line Numbers
  1. import ImageGrab,pythoncom,pyHook,os
  2. from datetime import *
  3. def OnKeyboardEvent(event):
  4.    if(event.Key=="F7"):
  5.       #catching the f7 event
  6.       s=getDateInString()
  7.       aux=r"C:\\ScreenShots\\ss"
  8.       path=aux+s+".jpg"
  9.       print path
  10.       img = ImageGrab.grab()
  11.       img.save(path)
  12.    return True
  13. def getDateInString():
  14.    #tunning the path
  15.    s=str(datetime.today()).split(' ')
  16.    return s[0]+'-'+s[1].replace(':','-').split('.')[0]
  17. # if dont exist, create directory where all ss will be saved
  18. if(os.access("C:\\ScreenShots",os.F_OK)==False):
  19.    os.mkdir("C:\\ScreenShots")
  20. # create a hook manager
  21. hm = pyHook.HookManager()
  22. # watch for all mouse events
  23. hm.KeyDown = OnKeyboardEvent
  24. # set the hook
  25. hm.HookKeyboard()
  26. # wait forever
  27. pythoncom.PumpMessages()
  28.  


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).
May 25 '07 #7
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!
May 25 '07 #8
bartonc
6,596 Expert 4TB
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 "environment" for your utility to live in.
May 25 '07 #9
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 "environment" for your utility to live in.

Thanks! man you rock!!
May 25 '07 #10
bartonc
6,596 Expert 4TB
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.
May 25 '07 #11
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!
May 25 '07 #12
bartonc
6,596 Expert 4TB
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.
May 25 '07 #13
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.exe"?
May 26 '07 #14
bartonc
6,596 Expert 4TB
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.exe"?
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!
Expand|Select|Wrap|Line Numbers
  1. # Py2Exe version 6.3 setup file for wxPython GUI programs.
  2. # Creates a single exe file.
  3. # It's easiest to add this wxPython2Exe.py file into the same
  4. # folder with the source file and an optional iconfile like "icon.ico"
  5. # (if you add your own icon file, remove the comment in front of icon_resources).
  6. # Simply change the filename to whatever you called your source file.
  7. # Optionally edit the version info and add the name of your icon file.
  8. # Now run wxPython2Exe.py ...
  9. # Two subfolders will be created called build and dist.
  10. # The dist folder contains your .exe file, MSVCR71.dll and w9xpopen.exe
  11. # Your .exe file contains your code, all neded modules and the Python interpreter.
  12. # The MSVCR71.dll can be distributed, but is often already in the system32 folder.
  13.  
  14. from distutils.core import setup
  15. import py2exe
  16. import sys
  17.  
  18.  
  19. # enter the filename of your wxPython code file to compile ...
  20. filename = "ImageGrabber.py"
  21.  
  22. # ... this creates the filename of your .exe file in the dist folder
  23. if filename.endswith(".py"):
  24.     distribution = filename[:-3]
  25. elif filename.endswith(".pyw"):
  26.     distribution = filename[:-4]
  27.  
  28.  
  29. # if run without args, build executables in quiet mode
  30. if len(sys.argv) == 1:
  31.     sys.argv.append("py2exe")
  32.     sys.argv.append("-q")
  33.  
  34. class Target:
  35.     def __init__(self, **kw):
  36.         self.__dict__.update(kw)
  37.         # for the versioninfo resources, edit to your needs
  38.         self.version = "0.0.1"
  39.         self.company_name = "freddypyther"
  40.         self.copyright = "no copyright"
  41.         self.name = "Background Image Grabber"
  42.  
  43. ################################################################
  44. # The manifest will be inserted as resource into your .exe.  This
  45. # gives the controls the Windows XP appearance (if run on XP ;-)
  46. #
  47. # Another option would be to store it in a file named
  48. # test_wx.exe.manifest, and copy it with the data_files option into
  49. # the dist-dir.
  50. #
  51. manifest_template = '''
  52. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  53. <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  54. <assemblyIdentity
  55.     version="5.0.0.0"
  56.     processorArchitecture="x86"
  57.     name="%(prog)s"
  58.     type="win32"
  59. />
  60. <description>%(prog)s Program</description>
  61. <dependency>
  62.     <dependentAssembly>
  63.         <assemblyIdentity
  64.             type="win32"
  65.             name="Microsoft.Windows.Common-Controls"
  66.             version="6.0.0.0"
  67.             processorArchitecture="X86"
  68.             publicKeyToken="6595b64144ccf1df"
  69.             language="*"
  70.         />
  71.     </dependentAssembly>
  72. </dependency>
  73. </assembly>
  74. '''
  75.  
  76. RT_MANIFEST = 24
  77.  
  78. # description is the versioninfo resource
  79. # script is the wxPython code file
  80. # manifest_template is the above XML code
  81. # distribution will be the exe filename
  82. # icon_resource is optional, remove any comment and give it an iconfile you have
  83. #   otherwise a default icon is used
  84. # dest_base will be the exe filename
  85. test_grabber = Target(
  86.     description = "A non-GUI app",
  87.     script = filename,
  88.     other_resources = [(RT_MANIFEST, 1, manifest_template % dict(prog=distribution))],
  89.     #icon_resources = [(1, "icon.ico")],
  90.     dest_base = distribution)
  91.  
  92. ################################################################
  93. excludes = ["pywin.debugger", "pywin.debugger.dbgcon",
  94.             "pywin.dialogs", "pywin.dialogs.list",
  95.             "Tkconstants","Tkinter","tcl",
  96.             ] # "pywin",
  97. includes = ['PIL._imaging', 'pyHook.cpyHook']
  98.  
  99. setup(
  100.     # Need a console to be able to kill this non-GUI deamon #
  101. ##    windows = [test_grabber,],
  102. ##    console = [filename],
  103.     console = [test_grabber],
  104.     options = {"py2exe": {"compressed": 1,
  105.                           "optimize": 2,
  106.                           "ascii": 1,
  107.                           "bundle_files": 1,
  108.                           "packages":["PIL", "pyHook",],
  109.                           "excludes":excludes,
  110.                           "includes":includes}}, #
  111.     zipfile = None,
  112.     )
  113.  
May 27 '07 #15
bartonc
6,596 Expert 4TB
By the way, here's my ImageGrabber.py:
Expand|Select|Wrap|Line Numbers
  1. """ImageGrabber.py: Grabs a screenshot and save it to a file with a dated name."""
  2.  
  3. import ImageGrab, pythoncom, pyHook, os
  4. from datetime import *
  5.  
  6. if(os.access("C:\\ScreenShots",os.F_OK)==False):
  7.     # if dont exist, create directory where all ss will be saved
  8.     os.mkdir("C:\\ScreenShots")
  9.  
  10. def getDateInString():
  11.     #tunning the path
  12.     s = str(datetime.today()).split(' ')
  13.     return s[0]+'-'+s[1].replace(':', '-').split('.')[0]
  14.  
  15. def OnKeyboardEvent(event):
  16.     print "Got a keyboard event"
  17.     if(event.Key == "F7"):
  18.         #catching the f7 event
  19.         s = getDateInString()
  20.         aux = r"D:\\ScreenShots\\ss"
  21.         path = aux + s + ".jpg"
  22.         print path
  23.         img = ImageGrab.grab()
  24.         img.save(path)
  25.     return True
  26.  
  27. print "Setting up the Grabber"
  28. # create a hook manager
  29. hm = pyHook.HookManager()
  30. # watch for all KeyDown events
  31. print hm
  32. hm.SubscribeKeyDown(OnKeyboardEvent)
  33. # set the hook
  34. hm.HookKeyboard()
  35. # wait forever
  36. pythoncom.PumpMessages()
  37.  
May 27 '07 #16
OH!! thank you very much man!!! let's see if I could end this project up.
May 28 '07 #17
Well, I've had some errors trying to run successfully the setup.py, some windows DLL and some quite difficult stuff for me. I'm so grateful for your help. I'm wondering that if the problem is with the module PyHook, maybe Tkinter can catch keyevents the same way it does pyhook? It could be worth that I try to do it with tkinter instead of pyHook, then I'll just have to take care about the ImageGrab module if there is some error with modules.

Thanks for all your help!
May 28 '07 #18
bartonc
6,596 Expert 4TB
Well, I've had some errors trying to run successfully the setup.py, some windows DLL and some quite difficult stuff for me. I'm so grateful for your help. I'm wondering that if the problem is with the module PyHook, maybe Tkinter can catch keyevents the same way it does pyhook? It could be worth that I try to do it with tkinter instead of pyHook, then I'll just have to take care about the ImageGrab module if there is some error with modules.

Thanks for all your help!
There is a screen grabber example in Tkinter, somewhere. I'll have a look around and see if I can find that for you. I used to use it back before I knew about the PtrScn button on my keyboard.
May 28 '07 #19
bartonc
6,596 Expert 4TB
There is a screen grabber example in Tkinter, somewhere. I'll have a look around and see if I can find that for you. I used to use it back before I knew about the PtrScn button on my keyboard.
Nope, not Tkinter. It's win32. On my system the path is "D:\Python24\Lib\site-packages\win32\Demos" and the file is called "print_desktop.py". Good luck.
May 28 '07 #20
Well I've been trying for long time with no succeed :( . So the only thing I can do now is ask if someone know how to get the "sstaker.exe" if he/she could create it and send it to me via email or something (I know it's a dangerous stuff but I don't know how to create that exe, hundreds of windows dll errors with no solucion).

Thanks again to all !
Jun 1 '07 #21

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: QQ June | last post by:
Hello, I have some java classes. But, I don't want my users to type "java my_java_program" every time they run the java class ? How do I pack them together into one executable file, like...
0
by: Martin Bless | last post by:
I need to access a MSSQL database (MS-Sql, not MySQL!)and would very much like to use mssql-0.09.tar.gz which is available from http://www.object-craft.com.au/projects/mssql/download.html ...
3
by: Seelan Rajagopal | last post by:
Hey Guys! Im Compiling a simple program is the command promt. I have set all the paths needed to run the compiler. But when I use csc myprogram.cs, it says that the program does not have an entry...
4
by: Aaron Queenan | last post by:
When I build a C++ library to .NET using the managed C++ compiler, I get the following error message: Linking... LINK : error LNK2020: unresolved token (0A000005) _CrtDbgReport LINK : error...
2
by: Rudy Ray Moore | last post by:
Hi guys, I just upgraded to "Visual Studio .net 2003 7.1 c++" from VS6. Some things I like (proper for loop variable scoping, for example), but some other things are troubling me. One...
10
by: Christina N | last post by:
When compiling my ASP.Net application, VS puts the new DLL under the local cached directory 'VSWebCache' in stead of on the server. How can I make it save the DLL file on the server when compiling?...
19
by: Simon Faulkner | last post by:
Pardon me if this has been done to death but I can't find a simple explanation. I love Python for it's ease and speed of development especially for the "Programming Challenged" like me but why...
5
by: NvrBst | last post by:
I'm wondering if this is possible... Basically say I have a lot of .cs files but only 1 of them changes. Is there a way (with the csc.exe, or VS.NET 2005, or another C# Compiler), that I can...
0
by: =?Utf-8?B?amVmZmVyeQ==?= | last post by:
i need help compiling code dynamically it may involve some reflection so if any one is any good in that field or compiling code this would be a great time to show me what you know. by the way my...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.