2

我目前正在尝试使用https://www.tensorflow.org/guide/upgrade中提供的 jupyter notebook升级脚本以与tensorflow2兼容,以便我可以在 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') ,但在这种情况下我一无所知。我不是程序员,所以我的能力非常有限。请帮助我理解这个错误。

4

1 回答 1

2

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

于 2020-09-17T03:49:03.727 回答