-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build Failure with UnicodeDecodeError #10551
Comments
Interesting. It looks like python3 is choosing to use the system default rather than utf8. I see a PEP out that fixes this: https://www.python.org/dev/peps/pep-0597/ In the mean time we should probably force utf8 somehow. |
This seems to mostly be a problem on windows. There is even a PEP out to make this the default: https://www.python.org/dev/peps/pep-0597 Fixes: #10551
This seems to mostly be a problem on windows. There is even a PEP out to make this the default: https://www.python.org/dev/peps/pep-0597 Fixes: #10551
Re-opening because fix got revertted. |
if you set |
Thank you for your comment. after setting environment variable "PYTHONUTF8" to 1, compiling my project on python 3.7.7 has succeeded. |
I've having a similar issue, but setting PYTHONUTF8=1 does not seem to have an effect. Is there something else may be changed to work around this issue ? (I removed the stack trace it was the same as above) |
Does setting PYTHONIOENCODING=utf8 instead of PYTHONUTF8=1 resolve your problem? |
@nokotan thanks for the help. It's not having any effect, unfortunately. It looks like the ascii decoder is still used in subprocess. I'll update my running Python, must be related. |
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant. |
I can no longer reproduce this problem with latest emscripten, keeping this issue closed as stale bot just closed this issue. |
@nokotan I reproduce this problem with emcc --version 2.0.3; command: emcc index.cc --pre-js pre.js -o index.js // pre.js
Module = {};
Module.onRuntimeInitialized = function () {
postMessage("Worker Ready.");
};
self.onmessage = function (e) {
console.log("哈哈: data from Main-js:" + e.data);
console.log("开始: start.");
var p = Module._Pi(e.data);
postMessage(p);
console.log("Worker: 结束.");
}; // index.cc
int main()
{
int64_t a = 9223372036854775806; //0x7FFFFFFFFFFFFFFE
a += 1;
printf("%lld\n", a);
} When The Error Tips: |
What encoding is your file in? It seems that python is trying to use an encoding called |
@sbc100 Thank you for your reply. OS: Windows 10 Home version 1909 I have found the cause of this problem . // line 2778
elif check_arg('--pre-js'):
options.pre_js += open(consume_arg_file()).read() + '\n' The third parameter Encoding is not specified, and my pkg.js is utf-8 encoding, so an error occurs when python opening the file。 (function) open: (file: _OpenFile, mode: str, buffering: int = ..., encoding: str | None = ..., errors: str | None = ..., newline: str | None = ..., closefd: bool = ..., opener: _Opener | None = ...) -> IO
Open file and return a stream. Raise OSError upon failure.
file is either a text or byte string giving the name (and the path if the file isn't in the current working directory) of the file to be opened or an integer file descriptor of the file to be wrapped. (If a file descriptor is given, it is closed when the returned I/O object is closed, unless closefd is set to False.)
mode is an optional string that specifies the mode in which the file is opened. It defaults to 'r' which means open for reading in text mode. Other common values are 'w' for writing (truncating the file if it already exists), 'x' for creating and writing to a new file, and 'a' for appending (which on some Unix systems, means that all writes append to the end of the file regardless of the current seek position). In text mode, if encoding is not specified the encoding used is platform
dependent: locale.getpreferredencoding(False) is called to get the current locale encoding. (For reading and writing raw bytes use binary mode and leave encoding unspecified.) The available modes are:
Character Meaning
'r' open for reading (default)
'w' open for writing, truncating the file first
'x' create a new file and open it for writing
'a' open for writing, appending to the end of the file if it exists
'b' binary mode
't' text mode (default)
'+' open a disk file for updating (reading and writing)
'U' universal newline mode (deprecated)
The default mode is 'rt' (open for reading text). For binary random access, the mode 'w+b' opens and truncates the file to 0 bytes, while 'r+b' opens the file without truncation. The 'x' mode implies 'w' and raises an FileExistsError if the file already exists.
Python distinguishes between files opened in binary and text modes, even when the underlying operating system doesn't. Files opened in binary mode (appending 'b' to the mode argument) return contents as bytes objects without any decoding. In text mode (the default, or when 't' is appended to the mode argument), the contents of the file are returned as strings, the bytes having been first decoded using a platform-dependent encoding or using the specified encoding if given.
'U' mode is deprecated and will raise an exception in future versions of Python. It has no effect in Python 3. Use newline to control universal newlines mode.
buffering is an optional integer used to set the buffering policy. Pass 0 to switch buffering off (only allowed in binary mode), 1 to select line buffering (only usable in text mode), and an integer > 1 to indicate the size of a fixed-size chunk buffer. When no buffering argument is given, the default buffering policy works as follows:
Binary files are buffered in fixed-size chunks; the size of the buffer is chosen using a heuristic trying to determine the underlying device's "block size" and falling back on io.DEFAULT_BUFFER_SIZE. On many systems, the buffer will typically be 4096 or 8192 bytes long.
"Interactive" text files (files for which isatty() returns True) use line buffering. Other text files use the policy described above for binary files.
encoding is the name of the encoding used to decode or encode the file. This should only be used in text mode. The default encoding is platform dependent, but any encoding supported by Python can be passed. See the codecs module for the list of supported encodings.
...
... Among them, the description of
It can be seen that when I think this solution is a bit complicated, but I don't know if there is a better way to solve this error. |
I see, so it sounds like there is not much emscripten can do to solve that problem is there? If a user sets their default encoding to "GBK" then we should probably reasonably expect their source code to be encoded using this encoding I guess? The alternative would be to force UTF-8 but that sounds just likely to cause issues for uses. |
@sbc100 Perhaps, Emscripten can allow passing the third parameter But I don’t know if it is necessary. |
Maybe this issue will be affected by #16736? |
Compilation to web target is currently failing with the following bug (debug lines obtained with EMCC_DEBUG=1): make raylib_game make[1]: Entering directory '/home/fcasas/Music/nokia-pod-racer/src' emcc -o raylib_game.html raylib_game.o screen_logo.o screen_title.o screen_options.o screen_gameplay.o screen_ending.o -std=c99 -Wall -Wno-missing-braces -Wunused-result -D_DEFAULT_SOURCE -Os -s MINIFY_HTML=0 -I. -I/home/fcasas/Videos/raylib-web/src -I/home/fcasas/Videos/raylib-web/src/external -I/home/fcasas/Videos/raylib-web/src/extras -L. -L/home/fcasas/Videos/raylib-web/src -L/home/fcasas/Videos/raylib-web/src -s USE_GLFW=3 -s TOTAL_MEMORY=134217728 -s FORCE_FILESYSTEM=1 --preload-file resources --shell-file minshell.html /home/fcasas/Videos/raylib-web/src/libraylib.a -DPLATFORM_WEB ... emcc:DEBUG: minifying HTML file raylib_game.html profiler:DEBUG: block "final emitting" raised an exception after 0.066 seconds profiler:DEBUG: block "post_link" raised an exception after 3.469 seconds profiler:DEBUG: block "main" raised an exception after 3.653 seconds Traceback (most recent call last): File "/usr/share/emscripten/emcc.py", line 3929, in <module> sys.exit(main(sys.argv)) File "/usr/lib/python3.10/contextlib.py", line 79, in inner return func(*args, **kwds) File "/usr/share/emscripten/emcc.py", line 3922, in main ret = run(args) File "/usr/share/emscripten/emcc.py", line 1194, in run phase_post_link(options, state, wasm_target, wasm_target, target) File "/usr/lib/python3.10/contextlib.py", line 79, in inner return func(*args, **kwds) File "/usr/share/emscripten/emcc.py", line 2740, in phase_post_link phase_final_emitting(options, state, target, wasm_target, memfile) File "/usr/lib/python3.10/contextlib.py", line 79, in inner return func(*args, **kwds) File "/usr/share/emscripten/emcc.py", line 2867, in phase_final_emitting generate_html(target, options, js_target, target_basename, File "/usr/share/emscripten/emcc.py", line 3663, in generate_html minify_html(target) File "/usr/share/emscripten/emcc.py", line 3637, in minify_html shared.check_call(['htmlmin', opts, '--', filename, filename]) File "/usr/share/emscripten/tools/shared.py", line 221, in check_call return run_process(cmd, *args, **kw) File "/usr/share/emscripten/tools/shared.py", line 105, in run_process ret = subprocess.run(cmd, check=check, input=input, *args, **kw) File "/usr/lib/python3.10/subprocess.py", line 501, in run with Popen(*popenargs, **kwargs) as process: File "/usr/lib/python3.10/subprocess.py", line 969, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/usr/lib/python3.10/subprocess.py", line 1778, in _execute_child self.pid = _posixsubprocess.fork_exec( TypeError: expected str, bytes or os.PathLike object, not list This seems related to this bug in emscripten: emscripten-core/emscripten#10551 The solution is doing the same as in: emscripten-core/emscripten#8547 adding the following compilation flag: CFLAGS += -s MINIFY_HTML=0
Updating EMSDK (Python 2.x to Python 3.7) results build error (seems to be encoding problem)
OS: Windows 10 Home version 1909
Language: Japanese
Project Files:
https://github.com/nokotan/DxLibForHTML5-VSCode
Command:
Traceback:
The text was updated successfully, but these errors were encountered: