1.

Solve : [Python] py2exe exe not responding?

Answer»

I assume from the lack of responces to other python questions, that there isn't anyone else that writes python code here, but I am having a PROBLEM with py2exe. The code runs fine in python interpreter, but when I 'compile' it via py2exe, it stops responding. Any ideas?

Code: [Select]from ctypes import windll, Structure, c_long, byref
import os
import win32gui
import win32api
import time
from PIL import Image,ImageDraw,ImageTk


key = ord('Z')
delay = 1
hashmap = {}
last20 = []
log_write='w'


# Declares deta type Point, which allows queryMousePossition to return two values
class POINT(Structure):
_fields_ = [("x", c_long), ("y", c_long)]

# Recalls cursor position and returns it as array values.
def queryMousePosition():
pt = POINT()
windll.user32.GetCursorPos(byref(pt))
return { "x": pt.x, "y": pt.y}
def queryKeyPress():
ky = win32api.GetAsyncKeyState(key)
return ky

ky = 0
print "PRESS '%s' to Start" %chr(key)
while ky == 0 or ky == 1:
pos = queryMousePosition()
ky = queryKeyPress()
print "\r \r(%s,%s)" % (pos["x"],pos["y"]), # for debug
print "\r "



i = delay
while i > 0:
print " \rStarting in %d SECONDS" % i,
time.sleep(1)
i-=1
print "\r "


ky = 0
log = open('log.txt',log_write)
print "Press '%s' to Halt" % chr(key)
while ky == 0 or ky == 1:
lastpoint=""
pos = queryMousePosition()
pos=str(pos["x"])+","+str(pos["y"])
ky = queryKeyPress()
last20.insert(0,pos)
while len(last20) > 20:
lastpoint = last20.pop()
print "\r \r("+pos+")", # for debug
amount = ""
if not(lastpoint == pos):
try:
amount = hashmap[pos]
log.write(pos+"\n")
except:
amount = 0
amount+=1
hashmap[pos] = amount
log.close()



print "Processing Data"
ch = 0
total=0
for x in hashmap:
if hashmap[x] > ch:
ch = hashmap[x]
total+=1
div = 255.000000/ch*2

img = Image.new("RGB",(win32api.GetSystemMetrics(0)/2, win32api.GetSystemMetrics(1)/2), 'white')
pen = ImageDraw.Draw(img)
lines = []
inc=0
for x in hashmap:
c = x.split(',')
h = str(hex(INT((div*(ch/hashmap[x]))))).replace("0x","")
if len(h) < 2:
h="0"+h
h = "#"+h+h+h
pen.point((int(c[0])/2,int(c[1])/2), fill=(h))
inc+=1
print x,str(hashmap[x]),"/",ch,h
#print "\r \r%d/%d" % (inc,total),
img.save("log.png")


ky = 0
print "Press '%s' to Exit" %chr(key)
while ky == 0 or ky == 1:
ky = queryKeyPress()
Are you using the 32 or 64 bit version of py2exe and on a 32 or 64 bit os? Friend of mine I sent a message on FB about this who dabbles with python and has made stand alone exe's using py2exe stated something about the 64 bit version being buggy and the 32-bit version being better. Also he said make sure you have the newest version in case there are any bug fixes for the issue your having.

Other than that he mentioned something about any legacy scripting techniques maybe not being supported under the py2exe and choking it up or missing dependencies for py2exe when it compiles, however a missing dependency should give an error message.

Hope this helps...

Thanks, I'll check on the version of py2exe that's installed. I've only just started using py2exe (as in this is the first test) and I'm using someone else's script to run it. The problem might also be in that.

Code: [Select]import sys
from distutils.core import setup
import py2exe

entry_point = sys.argv[1]
sys.argv.pop()
sys.argv.append('py2exe')
sys.argv.append('-q')

opts = {
'py2exe': {
'compressed': 1,
'optimize': 2,
'bundle_files': 1
}
}

setup(console=[entry_point], options=opts, zipfile=None)
where the script to be compiled is passed in as the first argument (Python setup.py script.py)


EDIT:
It was the setup.py file, I rewrote it and now it compiles. Thanks for the advice about the 64bit version.



Discussion

No Comment Found