運行 Tensorflow2 升級腳本會觸發編碼錯誤 (Running the Tensorflow2 upgrade Script triggers an encoding error)


問題描述

運行 Tensorflow2 升級腳本會觸發編碼錯誤 (Running the Tensorflow2 upgrade Script triggers an encoding error)

我目前正在嘗試使用 https://www.tensorflow.org/guide/upgrade,這樣我就可以在 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') ,但在這種情況下我一無所知。我不是程序員,所以我的能力非常有限。請幫助我理解這個錯誤。


參考解法

方法 1:

Try editing with open in line 918 of function process_file in ast_edits.py and specify encoding='utf‑8', so that in the function process_opened_file the file can be read with utf‑8.

(by Eric Avila TorresGreensky Woodson)

參考文件

  1. Running the Tensorflow2 upgrade Script triggers an encoding error (CC BY‑SA 2.5/3.0/4.0)

#upgrade #tensorflow2.x #encoding #jupyter-notebook






相關問題

我如何知道哪個應用程序版本正在被 android 替換? (How do I know which app version is being replaced with android?)

升級到 Mac OS Lion - 如何備份 Ruby、*SQL 等? (Upgrade to Mac OS Lion - how to backup Ruby, *SQL, etc?)

將 jQuery 1.4.2 升級到 1.9.1 (Upgrade jQuery 1.4.2 to 1.9.1)

將 Jquery.min 升級到 Jquery.1.9 時出錯 (Error Upgrade Jquery.min into Jquery.1.9)

Building Wix 3.0 升級和補丁 (Building Wix 3.0 upgrade and patch)

Rails flash 拋出錯誤數量的參數(0 代表 2)錯誤 (Rails flash is throwing wrong number of arguments (0 for 2) error)

操作系統升級後無法從 ANT 訪問環境變量 (Can't access env vars from ANT after OS upgrade)

從 Rails 1.x 轉換到 2.x 是否有任何機械幫助? (Is there any mechanical assistance in converting from Rails 1.x to 2.x?)

Team Foundation Server 2015 到 2018 升級錯誤(步驟 909) (Team Foundation Server 2015 to 2018 Upgrade Error (Step 909))

運行 Tensorflow2 升級腳本會觸發編碼錯誤 (Running the Tensorflow2 upgrade Script triggers an encoding error)

將 Angular 5 升級到 Angular 11 (Upgrade angular 5 to angular 11)

在 centOS 6.9 (Final) 中將 php-5.6 升級到 7.3 時顯示多個錯誤 (Showing multiple errors while upgrading php-5.6 to 7.3 in centOS 6.9 (Final))







留言討論