gpt4 book ai didi

encoding - 运行 Tensorflow2 升级脚本触发编码错误

转载 作者:行者123 更新时间:2023-12-04 10:38:41 24 4
gpt4 key购买 nike

我目前正在尝试升级脚本以兼容 tensorflow 2 通过使用 https://www.tensorflow.org/guide/upgrade 中提供的 jupyter notebook ,以便我可以在 google colab 中运行它,但是当我运行这个单元时(从 Windows 中的 Anaconda 环境):

!tf_upgrade_v2 \
--infile D:/Multiclass.py\
--outfile /tmp/upgraded_Multiclass_CNN_V01_31012020Copy.py

我收到一个编码错误:
 Traceback (most recent call last):
File "d:\programdata\miniconda3\envs\env_dlexp1\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "d:\programdata\miniconda3\envs\env_dlexp1\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "D:\ProgramData\Miniconda3\envs\Env_DLexp1\Scripts\tf_upgrade_v2.exe\__main__.py", line 7, in <module>
File "C:\Users\user\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\tools\compatibility\tf_upgrade_v2_main.py", line 139, in main
args.input_file, output_file, upgrade)
File "C:\Users\user\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\tools\compatibility\tf_upgrade_v2_main.py", line 40, in process_file
upgrader.process_file(in_filename, out_filename)
File "C:\Users\user\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\tools\compatibility\ast_edits.py", line 900, in process_file
temp_file)
File "C:\Users\user\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\tools\compatibility\ast_edits.py", line 958, in process_opened_file
lines = in_file.readlines()
File "d:\programdata\miniconda3\envs\env_dlexp1\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 0x81 in position 14: character maps to <undefined>

我通常会将编码更改为 utf-8 这样做: open(path, mode, encoding='UTF8'),但在这种情况下,我一无所知。我不是程序员,所以我的熟练程度非常有限。请帮助我理解这个错误。

最佳答案

尝试编辑 with open在函数的第 918 行 process_file在 ast_edits.py 中指定 encoding='utf-8',以便在函数 process_opened_file 中该文件可以用 utf-8 读取。

关于encoding - 运行 Tensorflow2 升级脚本触发编码错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60035966/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com