You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] UnicodeDecodeError on Windows due to missing encoding="utf-8" in open() call #2660
>>> import unsloth
🦥 Unsloth: Will patch your computer to enable 2x faster free finetuning.
🦥 Unsloth Zoo will now patch everything to make training faster!
Traceback (most recent call last):
File "<stdin>", line 1, in<module>
File "D:\diskA\git-repo\Hoopoes\unsloth-train\.venv\lib\site-packages\unsloth\__init__.py", line 247, in<module>
from .models import *
File "D:\diskA\git-repo\Hoopoes\unsloth-train\.venv\lib\site-packages\unsloth\models\__init__.py", line 15, in<module>
from .llama import FastLlamaModel
File "D:\diskA\git-repo\Hoopoes\unsloth-train\.venv\lib\site-packages\unsloth\models\llama.py", line 2757, in<module>
PatchFastRL(FastLanguageModel = FastLlamaModel)
File "D:\diskA\git-repo\Hoopoes\unsloth-train\.venv\lib\site-packages\unsloth\models\rl.py", line 810, in PatchFastRL
patch_trl_rl_trainers()
File "D:\diskA\git-repo\Hoopoes\unsloth-train\.venv\lib\site-packages\unsloth\models\rl.py", line 803, in patch_trl_rl_trainers
_patch_trl_rl_trainers(trainer)
File "D:\diskA\git-repo\Hoopoes\unsloth-train\.venv\lib\site-packages\unsloth\models\rl.py", line 597, in _patch_trl_rl_trainers
created_module = create_new_function(
File "D:\diskA\git-repo\Hoopoes\unsloth-train\.venv\lib\site-packages\unsloth_zoo\compiler.py", line 346, in create_new_function
with open(function_location, "r") as f: file_source = f.read()
File "C:\Users\umar-anzar\AppData\Roaming\uv\python\cpython-3.10.17-windows-x86_64-none\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 54390: character maps to <undefined>
Root Cause:
In unsloth_zoo/compiler.py, the open() function is used without specifying encoding="utf-8".
Temporary Workaround:
This was resolved by setting the following environment variable via the Windows System Settings (not via Python):
PYTHONUTF8=1
Kindly handle UTF-8 encoding in file reads so we don't have to rely on setting PYTHONUTF8=1 as a workaround.
Reacted by SecaraR, Elieder Gomes, Lincoln Zhou, Hoi, Tongyao(Cornelia) Wang, M Hendra Herviawan and Tiberiu-Ioan Szatmari
Reacted by Erik Zimmermann and Tiberiu-Ioan Szatmari
This should be fixed now - sorry on the delay - please update with uv pip install --upgrade unsloth unsloth_zoo --force-reinstall --no-cache-dir - if it's not fixed yet, it'll be in the next pip / PyPI release - if it's still not working after that, please open another issue - appreciate it again!
Activity
shikage commentedon Jun 18, 2025
I can confirm I am getting the same error on a Windows 11 system.
erikzimmermann commentedon Jun 21, 2025
Getting the same error on Windows 11. Adding the env variable fixed it for me.
abdullahsultan commentedon Jul 15, 2025
Also getting this annoying error Win11, that temp solution worked for me. Thanks
fix: Windows compatibility encoding, cross-platform builds, sys.execu…
fix: decode subprocess output as UTF-8 in save.py on Windows (#6218)
danielhanchen commentedon Jun 18, 2026
This should be fixed now - sorry on the delay - please update with
uv pip install --upgrade unsloth unsloth_zoo --force-reinstall --no-cache-dir- if it's not fixed yet, it'll be in the next pip / PyPI release - if it's still not working after that, please open another issue - appreciate it again!Keep the LoRA GGUF and compressed-tensors converters off the operator…
OpenVINO export: trust remote code only for a remote-code model, and …
OpenVINO export: trust remote code only for a remote-code model, and …
fix: decode llama.cpp subprocess output as UTF-8 on Windows (#764)