I have a simple python/pyqt application that is inserting data into a SQLITE database table, some of the entries contain special characters such as umlauts. I did the development using eclipse, tested it and managed to insert all the data without any errors. I then decided to create an executable, of my application. I am using py2exe to create the executable. My setup.py looks as follows
from distutils.core import setup
import py2exe
import os
includes=["sqlite3","sip","PyQt4", "PyQt4.QtGui"]
excludes=[]
packages=[]
dll_excludes=['libgdk-win32-1.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll', 'tk84.dll']
setup(
options={"py2exe": {"compressed": 2,
"optimize": 2,
"includes": includes,
"excludes": excludes,
"packages": packages,
"dll_excludes": dll_excludes,
"bundle_files": 2,
"dist_dir": "dist",
"xref": False,
"skip_archive": False,
"ascii": False,
"custom_boot_script": '',
}
},
windows=['MainWindow.py'],
)
It seems to work in as far as I get an executable application in a "dist" folder, when I run it, it loads fine, When I insert the same data, it falls over at the special characters(umlauts). of 100 entries I successfully insert 60, the first occurrence of an accented character causes the executable to fall over with the error message
(, UnicodeEncodeError('ascii', u'Citro\xebnCX', 5, 6, 'ordinal not in range(128)'), )
Just so happens I was inserting CitroenCX into the table, the 'e' being the french accented character
I don't know why when I run the python/pyqt application from my eclipse environment, I get no errors, but once I create an executable i get this error.
What changes should I make in my setup file
Thanks. I applied the solution
def setencoding():
encoding = "ascii"
if 0:
import locale
loc = locale.getdefaultlocale()
if loc[1]:
encoding = loc[1]
if 0: #changes comes here, change 0 to 1
encoding = "undefined" #the encoding you want
if encoding != "ascii":
sys.setdefaultencoding(encoding)
and it worked for me. Not an original solution, saw it on SO How to set default encoding in Python (setdefaultencoding() function does not exist)?