如何修复错误'UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 36188: character maps to '

18 浏览
0 Comments

如何修复错误'UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 36188: character maps to '

我正在使用TensorFlow 1.14和Python 2.6.7训练一个AI来写一本书。每当我运行我的训练Python代码时,我都会收到错误消息UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 36188: character maps to 。我已经重新安装了TensorFlow和Python,并在论坛上搜索以找到答案。回溯将我带到了一个名为cp1252.py的文件中,它位于encodings文件夹中。

我正在运行的代码是:

import numpy as np
import tensorflow as tf
import argparse
import time
import os
from six.moves import cPickle
from utils import TextLoader
from model import Model
def main():
    parser = argparse.ArgumentParser()
    # 其他参数...
    args = parser.parse_args()
    train(args)
def train(args):
    # 其他代码...
    data_loader = TextLoader(args.data_dir, args.batch_size, args.seq_length, args.input_encoding)
    # 其他代码...
if __name__ == '__main__':
    main()

任何帮助将不胜感激。我可以提供所需的任何信息。

我的回溯是:

File "train.py", line 134, in 
    main()
  File "train.py", line 54, in main
    train(args)
  File "train.py", line 57, in train
    data_loader = TextLoader(args.data_dir, args.batch_size, args.seq_length, args.input_encoding)
  File "C:\Users\Josh\Desktop\word-rnn-tensorflow-master\utils.py", line 23, in __init__
    self.preprocess(input_file, vocab_file, tensor_file, encoding)
  File "C:\Users\Josh\Desktop\word-rnn-tensorflow-master\utils.py", line 66, in preprocess
    data = f.read()
  File "C:\Users\Josh\anaconda3\envs\tensorenviron\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 36188: character maps to 

0