- Blender Part46
819 :806[sage]:2013/10/27(日) 16:04:30.98 ID:o0gjEXoB - とりあえずこれでエラーがでなくなった。
日本語とかは試してない。 ascii文字が普通にでてくれればいいので。 ---------------- import struct import sys import io import os print(sys.version) print(os.environ["PYTHONIOENCODING"]) print(sys.stdout.encoding) def e_utf8():sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', line_buffering=True) if sys.stdout.encoding == "cp932":e_utf8() a0=struct.unpack("f",b'\x9f\x9e\x9e>') a1=struct.unpack("f",b'\xc1\xc0@?') s="%f" % a0 t="%f" % a1 print("s=",s) print("t=",t) s+=t print(s) print("No problem")
| - Blender Part46
821 :806[sage]:2013/10/27(日) 18:20:38.89 ID:o0gjEXoB - blender2.68a\blender\source\blender\python\intern\bpy_interface.c
void BPY_python_start(int argc, const char **argv) { ... /* without this the sys.stdout may be set to 'ascii' * (it is on my system at least), where printing unicode values will raise * an error, this is highly annoying, another stumbling block for devs, * so use a more relaxed error handler and enforce utf-8 since the rest of * blender is utf-8 too - campbell */ /* XXX, update: this is unreliable! 'PYTHONIOENCODING' is ignored in MS-Windows * when dynamically linked, see: [#31555] for details. * Python doesn't expose a good way to set this. */ BLI_setenv("PYTHONIOENCODING", "utf-8:surrogateescape"); ... /* THIS IS BAD: see http://bugs.python.org/issue16129 */ /* this clobbers the stdout on exit (no 'MEM_printmemlist_stats') */ #if 0 /* until python provides a reliable way to set the env var */ PyRun_SimpleString("import sys, io\n" "sys.__backup_stdio__ = sys.__stdout__, sys.__stderr__\n" /* else we loose the FD's [#32720] */ "sys.__stdout__ = sys.stdout = io.TextIOWrapper(io.open(sys.stdout.fileno(), 'wb', -1), " "encoding='utf-8', errors='surrogateescape', newline='\\n', line_buffering=True)\n" "sys.__stderr__ = sys.stderr = io.TextIOWrapper(io.open(sys.stderr.fileno(), 'wb', -1), " "encoding='utf-8', errors='surrogateescape', newline='\\n', line_buffering=True)\n"); if (PyErr_Occurred()) { PyErr_Print(); PyErr_Clear(); } #endif
| - Blender Part46
824 :806[sage]:2013/10/27(日) 18:33:00.27 ID:o0gjEXoB - 解決策
1)batファイルでPYTHONIOENCODINGをsetしてblenderを起動する。 set PYTHONIOENCODING=utf-8:surrogateescape T:\blender-2.68a-windows32\blender.exe 2)ユーザー環境変数にPYTHONIOENCODINGを新規登録する。 テストスクリプト ---------- import os import sys print(os.environ) print(os.environ["PYTHONIOENCODING"]) print(sys.stdout.encoding) ----------- 最後がcp932ではなくutf-8になっていればok PythonConsoleでは sys.stdout.encoding はNone。
| - Blender Part46
825 :806[sage]:2013/10/27(日) 18:59:53.19 ID:o0gjEXoB - ユーザー環境変数の方は他のプログラムに影響がでるかも。
| - Blender Part46
832 :806[sage]:2013/10/27(日) 19:42:25.45 ID:o0gjEXoB - ttp://www.python.org/dev/peps/pep-0432/
further work on this PEP has been deferred to the Python 3.5 development cycle. ... and easier control of the encoding used for the standard IO streams when embedding CPython in a larger application [10]. [10] Problems with PYTHONIOENCODING in Blender (http://bugs.python.org/issue16129)
| - Blender Part46
834 :806[sage]:2013/10/27(日) 20:13:37.16 ID:o0gjEXoB - 3.4.0a4 に Py_SetStandardStreamEncoding が取り入れられたようなので
blenderが対応すれば解決ですね。 ttp://hg.python.org/cpython/file/e245b0d7209b/Include/pythonrun.h #ifndef Py_LIMITED_API /* Only used by applications that embed the interpreter and need to * override the standard encoding determination mechanism */ PyAPI_FUNC(int) Py_SetStandardStreamEncoding(const char *encoding, const char *errors); #endif ttp://hg.python.org/cpython/file/e245b0d7209b/Python/pythonrun.c
|
|