Correct way of using national encodings with non-utf system codepages and pyinstaller

324 views
Skip to first unread message

Alexey Kostylev

unread,
Nov 19, 2017, 5:47:50 AM11/19/17
to Kivy users support
Situation: the program is working OK from python, exe is created by pyinstaller (I installed ucrt runtime, and lost dlls were found), however after launching I have an error:

Fatal Python error: Py_Initialize: unable to load the file system codec
ImportError: No module named 'encodings'

Encodings are exactly present in base_library.zip, and were hooked:

68196 INFO: Loading module hook "hook-pydoc.py"...
68196 INFO: Loading module hook "hook-encodings.py"...
75684 INFO: Loading module hook "hook-encodings.py"...
84118 INFO: Loading module hook "hook-distutils.py"...
84118 INFO: Loading module hook "hook-distutils.py"...

Made an attemt to inwestigate the situation, launched out00-PYZ.pyz in build directory:

File "D:\Users\....\Kivy_UTF\build\Parser\out00-PYZ.pyz", line 1
SyntaxError: Non-UTF-8 code starting with '\x81' in file D:\Users\....\Kivy_UTF\build\Parser\out00-PYZ.pyz on line 2, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

System encoding is 1251

Added 
# -*- coding: utf-8 -*-
to all the sources (which are in utf), according to PEP-263, but no effect,adding

codecs.register(encodings.cp1251.Codec)

to '__main__ is negative too.

Win 10, the latest build. 

270 INFO: PyInstaller: 3.3
270 INFO: Python: 3.5.4
270 INFO: Platform: Windows-10-10.0.16299-SP0
...
[INFO   ] [Kivy        ] v1.10.0
286 INFO: [Kivy        ] v1.10.0
[INFO   ] [Python      ] v3.5.4 (v3.5.4:3f56838, Aug  8 2017, 02:17:05) [MSC v.1900 64 bit (AMD64)]
286 INFO: [Python      ] v3.5.4 (v3.5.4:3f56838, Aug  8 2017, 02:17:05) [MSC v.1900 64 bit (AMD64)]

Any advice? If it's simple, please, point me to RTFM, but I don't find it after Internet digging...

Alexey Kostylev

unread,
Nov 20, 2017, 2:23:03 PM11/20/17
to Kivy users support
Unfortunately, looks like to me, that the problem is somewhere in kivy, or I am using it wrongly. I made the simpliest test from two lines for checking pyinstaller:

print("english Test\n")
print("ФЫВАПРООЛЛДДЖЭЯЯССММИТТЬЬББЮБЮЙЦУКЕЕНГГШШЩЩЗЗЗХЪйцукенгшщзхъфывапролджэячсмитьбю")

After building this in pyinstaller the exe is printing OK. May save kv file and make a test later... Maybe, something may be in copy-paste, but the program is working, when launched by python *.py from commandline. Any advice?




воскресенье, 19 ноября 2017 г., 13:47:50 UTC+3 пользователь Alexey Kostylev написал:

Alexey Kostylev

unread,
Nov 25, 2017, 11:57:20 AM11/25/17
to Kivy users support
Investigating farther... The program below works OK as pyinstaller exe with huge pile of warnings about ucrt during building. Maybe, something in processing kv file... I'll continue resecrch.  

from kivy.app import App
from kivy.uix.button import Button

class TestApp(App):
def build(self):
return Button(text='ФЫВАПРООЛЛДДЖЭЯЯССММИТТЬЬББЮБЮЙЦУКЕЕНГГШШЩЩЗЗЗХЪйцукенгшщзхъфывапролджэячсмитьбю')

TestApp().run()



понедельник, 20 ноября 2017 г., 22:23:03 UTC+3 пользователь Alexey Kostylev написал:

Alexey Kostylev

unread,
Dec 20, 2017, 11:55:34 PM12/20/17
to Kivy users support
Success after the steps below:
  1. kv file is included in code, as a string. The string is LONG indeed :( but working. If read the file as usual (Builder.load_file('TEST.kv')) - encoding problems.
  2. Created a venv with the latest pycharm build. By the way, kivy may be added to venv by GUI only.
  3. Pyinstaller added to venv too, and all exe creating business was done in pycharm venv terminal (Alt-F12)

суббота, 25 ноября 2017 г., 19:57:20 UTC+3 пользователь Alexey Kostylev написал:

Alexey Kostylev

unread,
Jan 20, 2018, 2:52:08 AM1/20/18
to Kivy users support
Found another way, very close to regular samples. Works OK with 1251

str = open('res/kv/main.kv', 'r',encoding='utf-8').read()
Builder.load_string (str, rulesonly = True)
return MainWindow()

четверг, 21 декабря 2017 г., 7:55:34 UTC+3 пользователь Alexey Kostylev написал:
Reply all
Reply to author
Forward
0 new messages