python3.11.15编译安装
python3.11.15编译安装会遇到utf-8编码错误问题,python3.11引入deepfreeze机制导致,
gcc -pthread -c -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -std=c11 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -fvisibility=hidden -I./Include/internal -I. -I./Include -DPy_BUILD_CORE -o Python/frozen.o Python/frozen.c Traceback (most recent call last): File “/home/zhito/.pyenv/cache/Python-3.11.15/./Tools/scripts/deepfreeze.py”, line 23, in <module> identifiers, strings = get_identifiers_and_strings() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File “/home/zhito/.pyenv/cache/Python-3.11.15/Tools/scripts/generate_global_objects.py”, line 294, in get_identifiers_and_strings for name, string, *_ in iter_global_strings(): File “/home/zhito/.pyenv/cache/Python-3.11.15/Tools/scripts/generate_global_objects.py”, line 117, in iter_global_strings for lno, line in enumerate(infile, 1): File “/home/zhito/.pyenv/cache/Python-3.11.15/Lib/codecs.py”, line 322, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0x88 in position 0: invalid start byte
打开Tools/scripts/generate_global_objects.py文件,将iter_global_strings函数下的with open(filename, “rt”, encoding=”utf-8″,)更改为with open(filename, “rt”, encoding=”utf-8″, errors=”replace”),errors='replace' 的作用:遇到无法 utf8 解码的字节,直接替换成�字符,不再抛出异常,脚本继续往下跑,就能顺利生成deepfreeze.c
