Py2Exe
Verfasst: Samstag 11. April 2015, 13:11
Hallo zusammen,
eine Frage zu py2exe, nachdem ich es seit gestern erfolglos versuche -.-
Skript test.py:
setup.py:
Problem: meine Exe lässt sich nicht ausführen (*surprise*), es kommt auch keine Fehlermeldung (das Programm starte ich entweder per Doppelklick oder direkt in der cmd) außer: "test.exe funktioniert nicht mehr. Es wird nach einer Lösung für das Problem gesucht."
In der CMD steht keine Fehlermeldung.
Mein Befehl für py2exe lautet: python setup.py py2exe -b 1
und auch schon: python setup.py py2exe
Ich lese seit gestern Nachmittag nun ForenEinträge etc. und komme zu dem Entschluss, dass PIL der Unruhestifter ist (habe hierzu: http://www.py2exe.org/index.cgi/py2exeAndPIL gelesen, allerdings nur halb verstanden...).
Nun habe ich als Alternativplan eine neue Datei erstellt und nacheinander alle Module importiert (um den wahren Unruhestifter herauszufiltern), und siehe da: tatsächlich ist es PIL.Image
Es muss m.M. gar nicht PIL sein, wenn es ein anderes Modul gibt, welches besser mit py2exe harmoniert und ebenfalls dieses "getdata()" (oder etwas vergleichbares) unterstützt.
Also meine Fragen:
1. hat jmd. ein TUT für py2exe + PIL, welches funktioniert?
2. gibt es eine ausreichend gute Alternative für PIL, welche meinen Ansprüchen genügt?
PS: PIL.Image wird lediglich in der Funktion "img" gebraucht, um die Daten aus dem Bild zu ziehen.
eine Frage zu py2exe, nachdem ich es seit gestern erfolglos versuche -.-
Skript test.py:
Code: Alles auswählen
#!/usr/bin/env python
import time
import PIL.Image
import numpy
import copy
from Tkinter import *
import tkMessageBox as tkm
def img(img_name):
#return from img_name a list with (0,1) for (white, black) and after every line "\n" (=> line-end) as 3D Array (x,y,element)
img = PIL.Image.open(img_name)
n_img = numpy.array(img.getdata())
#a_img = array with image-list
a_img = n_img.tolist()
for i in range(len(a_img)):
#black = 1, rest = 0
if a_img[i] not in range(0, 15):
a_img.pop(i)
a_img.insert(i, 0)
else:
a_img.pop(i)
a_img.insert(i, 1)
list_length1 = int(len(a_img)**0.5)
list_length2 = list_length1
a_img.insert(list_length1, "\n")
for i in range (1, list_length2):
#insert "line-end" ("\n")
list_length1 = list_length1+list_length2+1
a_img.insert(list_length1, "\n")
y=1
# print ''.join(map(str, a_img))
for i in range (len(a_img)):
element = a_img[i]
a_img.pop(i)
if element == "\n":
try:
x = i%((y-1)*(list_length2+1))+1
a_img.insert(i, [x, y, element])
y += 1
except ZeroDivisionError:
x = i+1
a_img.insert(i, [x, y, element])
y += 1
else:
try:
x = i%((y-1)*(list_length2+1))+1
a_img.insert(i, [x, y, element])
except ZeroDivisionError:
x = i+1
a_img.insert(i, [x, y, element])
return a_img
def line(img_list):
#return line-length and direction of each line in image as array
line_list = [] #all lines of the image as [start, stop]-element
# print "---------------------------"
data = 1
while data == 1:
first_element = 0
start_point = 0
try:
while first_element != 1: #looking for first "1" in image
first_element = img_list[start_point][2]
start_point += 1
else: #founding first "1" in image: img_list[start_point] = 1
#looking for next "1"
list_length = int(len(img_list)**0.5)
start_point = start_point-1 #start-point of line
end_point = start_point #end-point of line
it = img_list[start_point][1] -1 #iterator
if img_list[start_point+1][2] == "\n" or img_list[start_point+1][2] == 0:
#no right line
if img_list[start_point+list_length*it+it][2] == 0:
#no line down
line_list.append([img_list[start_point], img_list[end_point]])
# print "punkt bei " + str(img_list[end_point])
x = img_list[start_point][0]
y = img_list[start_point][1]
img_list.pop(start_point)
img_list.insert(start_point, [x, y, 0])
else:
#line down
try:
while img_list[end_point+list_length+1][2] == 1:
end_point = end_point+list_length+1
it += 1
line_list.append([img_list[start_point], img_list[end_point]])
ind = start_point
out = end_point
while ind <= out:
x = img_list[ind][0]
y = img_list[ind][1]
img_list.pop(ind)
img_list.insert(ind, [x, y, 0])
ind += list_length+1
# print "linie nach unten fuer " + str(img_list[end_point][1]-img_list[start_point][1] +1)
except:
# end of paper
line_list.append([img_list[start_point], img_list[end_point]])
ind = start_point
it2 = 1
while ind <= end_point:
x = img_list[ind][0]
y = img_list[ind][1]
img_list.pop(ind)
img_list.insert(ind, [x, y, 0])
ind += list_length+1
# print "linie (endpaper) nach unten fuer " + str(img_list[end_point][1]-img_list[start_point][1] +1)
elif img_list[end_point+1][2] == 1:
#right line
while img_list[end_point+1][2] == 1:
end_point += 1
line_list.append([img_list[start_point], img_list[end_point]])
# print "linie nach rechts fuer " + str(img_list[end_point][0]-img_list[start_point][0] +1)
ind = start_point
while ind <= end_point:
x = img_list[ind][0]
y = img_list[ind][1]
img_list.pop(ind)
img_list.insert(ind, [x, y, 0])
ind += 1
except: #white Paper
# print "no more Data found"
data = 0
# lst = deepcopy(img_list)
# for i in range(len(img_list)):
# element = img_list[i][2]
# lst.pop(i)
# lst.insert(i, element)
# print ''.join(map(str, lst))
return line_list
def open_file():
path = insert_path.get()
img_listing = img(path)
line_listing = line(img_listing)
lst = copy.deepcopy(img_listing)
for i in range(len(lst)):
element = lst[i][2]
lst.pop(i)
lst.insert(i, element)
a = ''.join(map(str, lst))
tkm.showinfo(title="Bild-Matrix", message=a)
tkm.showinfo(title="Bild-Matrix", message=line_listing)
def open_window():
caption = "Hello Stephan"
insert_text ="Name of image-file"
explanation1 = "Notice: Presently, image has to be stored \n in the same folder as program"
path_window = Tk()
path_window.title(caption)
Label(path_window, text = insert_text).grid(row=0, column=0, sticky=W)
global insert_path
insert_path = Entry(path_window)
insert_path.grid(row=0, column=1, padx=4)
Label(path_window, text = explanation1).grid(row=1, column=0, sticky=W)
Button(path_window, text='Quit', command=path_window.quit).grid(row=1, column=2, pady=4)
Button(path_window, text='Open File', command=open_file).grid(row=0, column=2, pady=4)
path_window.mainloop()
def main():
open_window()
if __name__=='__main__':
main()Code: Alles auswählen
from distutils.core import setup
import py2exe
import numpy
import copy
from Tkinter import *
import tkMessageBox
import PIL.Image
a = "test.py"
setup(console=[a])
options={r"py2exe":{r"includes": r'Tkinter',
r"includes": r'random',
r"includes": r're',
r"includes": r'struct',
r"includes": r'PIL',
r"includes": r'time',
r"includes": r'copy',
r"includes": r'numpy',
r"includes": r'Image',
r"includes": r'tkMessageBox',
'bundle_files': 1, 'compressed': True,
}}In der CMD steht keine Fehlermeldung.
Mein Befehl für py2exe lautet: python setup.py py2exe -b 1
und auch schon: python setup.py py2exe
Ich lese seit gestern Nachmittag nun ForenEinträge etc. und komme zu dem Entschluss, dass PIL der Unruhestifter ist (habe hierzu: http://www.py2exe.org/index.cgi/py2exeAndPIL gelesen, allerdings nur halb verstanden...).
Nun habe ich als Alternativplan eine neue Datei erstellt und nacheinander alle Module importiert (um den wahren Unruhestifter herauszufiltern), und siehe da: tatsächlich ist es PIL.Image
Es muss m.M. gar nicht PIL sein, wenn es ein anderes Modul gibt, welches besser mit py2exe harmoniert und ebenfalls dieses "getdata()" (oder etwas vergleichbares) unterstützt.
Also meine Fragen:
1. hat jmd. ein TUT für py2exe + PIL, welches funktioniert?
2. gibt es eine ausreichend gute Alternative für PIL, welche meinen Ansprüchen genügt?
PS: PIL.Image wird lediglich in der Funktion "img" gebraucht, um die Daten aus dem Bild zu ziehen.