Seite 1 von 2

Re: pyinstaller, cx_freeze unicode???

Verfasst: Sonntag 25. Juni 2006, 14:03
von BlackJack
DatenMetzgerX hat geschrieben:

Code: Alles auswählen

        for root, dir, files in os.walk(self.Folder):
            for file in files:
                if resize.isPicture(os.path.splitext(file)[-1], wildcard):
                    lCounter+=1L
Hat nichts mit Deinem Problem zu tun, aber man sollte keine Namen von eingebauten Funktionen/Typen, in diesem Fall `file`, verdecken.

Und dann ist das L bei der 1 überflüssig es sei denn Du arbeitest mit einer *sehr* alten Python-Version.

Zur Namensgebung selbst: Der Styleguide empfiehlt Grossschreibung und CamelCase nur für Klassennamen. Und das `l` vor `Counter` scheint diese hässliche ungarische Notation zu sein. Das es sich bei `Counter` um eine Zahl handelt sollte auch ohne `l` ersichtlich sein.

Verfasst: Montag 26. Juni 2006, 08:40
von gerold
DatenMetzgerX hat geschrieben:

Code: Alles auswählen

micha@micha-desktop:~/Desktop/cx_Freeze-3.0.2/image$ ./test
None
None
Hi DatenMetzgerX!

So wie es aussieht, ist das Problem, dass das Python-Programm, wenn es unter Linux gefreezed wurde, das Encoding von STDIN und STDOUT nicht herausfinden kann. Man erkennt das an den "None", die du im Beispiel zurück bekommen hast.

Wenn du statt diesem Code

Code: Alles auswählen

# Encodings herausfinden
out_enc = sys.stdout.encoding or sys.getfilesystemencoding()
print out_enc
err_enc = sys.stderr.encoding or sys.getfilesystemencoding()
print err_enc
das Encoding manuell angibst -- funktioniert es dann?

Code: Alles auswählen

# Encodings herausfinden
out_enc = "utf-8"
print out_enc
err_enc = "utf-8"
print err_enc
Wenn Ja, dann müssten wir nur noch herausbekommen, wie wir das Encoding direkt abfragen können. Mir schwebt da z.B. vor, dass man die Ausgabe von "locale" untersuchen könnte.

lg
Gerold
:-)

Verfasst: Montag 26. Juni 2006, 19:36
von DatenMetzgerX
So hatte Zeit zum Testen

Code: Alles auswählen

Exception in thread Thread-1:
Traceback (most recent call last):
  File "./main/buildmain/out1.pyz/threading", line 442, in __bootstrap
  File "./main/buildmain/out1.pyz/frmfolder", line 32, in run
  File "./main/buildmain/out1.pyz/os", line 291, in walk
  File "./main/buildmain/out1.pyz/os", line 291, in walk
  File "./main/buildmain/out1.pyz/os", line 281, in walk
  File "./main/buildmain/out1.pyz/posixpath", line 65, in join
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 4: ordinal not in range(128)
Selber Fehler wei am Anfang :(

Verfasst: Montag 26. Juni 2006, 22:09
von Python 47
Es wäre vielleicht hiflreich, wenn du den ganzen oder einen größeren Teil des Codes schicken würdest. :)

Verfasst: Montag 26. Juni 2006, 22:43
von DatenMetzgerX

Code: Alles auswählen

def Generate(self, event):
        """Verkleinert die eigentlichen Bilder"""
        
        if not resize.isEmpty(self.txtFolder.GetValue()) and not ( resize.isEmpty(self.txtHeight.GetValue()) and resize.isEmpty(self.txtWidth.GetValue()) and not resize.isEmpty(self.txtDestination.GetValue()) ):
            self.Enable(False)
            maximum = count(self.txtFolder.GetValue(), self)
            progress = wx.ProgressDialog("Status", u"Dateien werden gezählt", maximum,parent = self, style = wx.PD_AUTO_HIDE | wx.PD_CAN_ABORT | wx.PD_ELAPSED_TIME | wx.PD_REMAINING_TIME)
            #self.Status.Destroy()
            progress.Update(0, "Dateien werde umgeformt")
            wildcard = (".jpg", ".png", ".jpeg", ".gif", ".bmp")
            
            if resize.isEmpty(self.txtHeight.GetValue()):
                height = 0
                width = int(self.txtWidth.GetValue())
            elif resize.isEmpty(self.txtWidth.GetValue()):
                width = 0
                height = int(self.txtHeight.GetValue())
            else:
                height = int(self.txtHeight.GetValue())
                width = int(self.txtWidth.GetValue())
            
            lCounter = 0
            exit = True
            for dir, dirs, files in os.walk(self.txtFolder.GetValue()):
                subdir = string.split(dir, self.txtFolder.GetValue())[-1]
                for file in files:
                    if progress.Update(lCounter, file)==False:
                       exit = False
                       break
                    type = os.path.splitext(file)[-1]
                    #type = string.rsplit(file, ".", 1)[-1]
                    if resize.isPicture(type, wildcard):
                        if subdir:
                            #destination = self.txtDestination.GetValue() + subdir
                            destination = os.path.join(self.txtDestination.GetValue(), subdir)
                        else:
                            destination = self.txtDestination.GetValue()
                        if os.path.exists(destination) == False:
                            try:
                                os.makedirs(destination)
                            except IOError, ex:
                                resize.PrintError(self, str(ex))
                        
                        if not resize.isEmpty(self.txtPrefix.GetValue()):
                            filedest = self.txtPrefix.GetValue() + file
                        else:
                            filedest = file
                            
                        resize.resize(os.path.join(dir, file), os.path.join(destination, filedest), height, width)
                        lCounter+=1
                        progress.Update(lCounter)
                if exit == False:
                    break
            #self.Status2.Destroy()
            if exit == True:
                resize.PrintInformation(self, u"Grösse erfolgreich geändert", "Fertig")
            else:
                progress.Destroy()
                resize.PrintError(self, u"Abbruch durch den Benutzer")
            self.Enable(True)
        else:
            resize.PrintError(self, "Bitte alle Felder ausfüllen")

Verfasst: Montag 26. Juni 2006, 22:58
von gerold
Hi DatenMetzgerX!

Bitte unter Linux ausprobieren. Dieses Beispiel wird wahrscheinlich so nicht unter Windows funktionieren. Aber wenn es unter Linux funktioniert, dann sehe ich eine Lösung:

Code: Alles auswählen

#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-

# Achte auf das Coding. Das muss mit dem wirklichen Dateicoding zusammenpassen.

import sys
import encodings
import encodings.ascii
import encodings.utf_8
import encodings.iso8859_1
import encodings.iso8859_15
import encodings.mbcs
import encodings.cp850
import codecs

 
# Encodings
out_enc = "iso-8859-1"
err_enc = "iso-8859-1"
in_enc = "iso-8859-1"

# StdOut und StdErr umleiten -> Streamwriter mit korrektem Encoding
sys.stdout = codecs.getwriter(out_enc)(sys.__stdout__)
sys.stderr = codecs.getwriter(out_enc)(sys.__stderr__)
sys.stdin = codecs.getreader(in_enc)(sys.__stdin__) 


def Generate(self, event):
    """Verkleinert die eigentlichen Bilder"""
    
    if not resize.isEmpty(self.txtFolder.GetValue()) and not ( resize.isEmpty(self.txtHeight.GetValue()) and resize.isEmpty(self.txtWidth.GetValue()) and not resize.isEmpty(self.txtDestination.GetValue()) ):
        self.Enable(False)
        maximum = count(self.txtFolder.GetValue(), self)
        progress = wx.ProgressDialog("Status", u"Dateien werden gezählt", maximum,parent = self, style = wx.PD_AUTO_HIDE | wx.PD_CAN_ABORT | wx.PD_ELAPSED_TIME | wx.PD_REMAINING_TIME)
        #self.Status.Destroy()
        progress.Update(0, "Dateien werde umgeformt")
        wildcard = (".jpg", ".png", ".jpeg", ".gif", ".bmp")
        
        if resize.isEmpty(self.txtHeight.GetValue()):
            height = 0
            width = int(self.txtWidth.GetValue())
        elif resize.isEmpty(self.txtWidth.GetValue()):
            width = 0
            height = int(self.txtHeight.GetValue())
        else:
            height = int(self.txtHeight.GetValue())
            width = int(self.txtWidth.GetValue())
        
        lCounter = 0
        exit = True
        for dir, dirs, files in os.walk(self.txtFolder.GetValue()):
            subdir = string.split(dir, self.txtFolder.GetValue())[-1]
            for file in files:
                ...
                ...
                ...
lg
Gerold
:-)

Edit: Ich habe STDIN vergessen. (ungetestet)

Verfasst: Montag 26. Juni 2006, 23:10
von gerold
PS: Mehr fällt mir im Moment nicht dazu ein. Dazu müsste ich mehr Zeit haben.

Vielleicht fällt denen in der cx_Freeze-Mailinglist mehr dazu ein.

Zumindest eins wissen wir aus unseren Tests.
Unter Linux bekommen wir bei einem gefreezten Programm kein Ergebnis auf sys.stdin.encoding, sys.stdout.encoding und sys.getfilesystemencoding()

lg
Gerold
:-)

Verfasst: Donnerstag 29. Juni 2006, 21:09
von DatenMetzgerX
So hatte auch wiedermal Zeit :roll:

Code: Alles auswählen

  File "/home/micha/Desktop/cx_Freeze-3.0.2/initscripts/Console.py", line 26, in ?
    exec code in m.__dict__
  File "../../image resizer/main.py", line 28, in ?
    sys.stdout = codecs.getwriter(out_enc)(sys.__stdout__)
  File "/usr/lib/python2.4/codecs.py", line 752, in getwriter
    return lookup(encoding)[3]
LookupError: unknown encoding: iso-8859-1
hmmm...Kennt das Encoding nicht :(
Auf Coding beim Speichern geachtet :)