尝试导入tensorflow时出现UnicodeDecodeError

时间:2018-05-01 14:42:25

标签: python tensorflow

我已经看到其他人使用tf的UnicodeDecodeErrors,但似乎总是因为他们正试图读取非拉丁字符的文件。我只是通过执行" import tensorflow"来收到此错误,因此我不确定我的错误来自哪里。

我使用的是Python 3.6.5,运行Windows 10,并通过pip安装了Tensorflow,因此它应该是最新的稳定版本。

以下是我试图进入"导入tensorflow"的错误:

Traceback (most recent call last):
  File "C:\Users\jp11cy\AppData\Local\Programs\Python\Python36\lib\tokenize.py", line 390, in find_cookie
    line_string = line.decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa0 in position 10: invalid start byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\jp11cy\AppData\Local\Programs\Python\Python36\lib\idlelib\run.py", line 474, in runcode
    exec(code, self.locals)
  File "<pyshell#0>", line 1, in <module>
  File "C:\Users\jp11cy\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "C:\Users\jp11cy\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\__init__.py", line 81, in <module>
    from tensorflow.python import keras
  File "C:\Users\jp11cy\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\keras\__init__.py", line 26, in <module>
    from tensorflow.python.keras import activations
  File "C:\Users\jp11cy\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\keras\activations\__init__.py", line 22, in <module>
    from tensorflow.python.keras._impl.keras.activations import elu
  File "C:\Users\jp11cy\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\keras\_impl\keras\__init__.py", line 21, in <module>
    from tensorflow.python.keras._impl.keras import activations
  File "C:\Users\jp11cy\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\keras\_impl\keras\activations.py", line 24, in <module>
    from tensorflow.python.keras._impl.keras.utils.generic_utils import deserialize_keras_object
  File "C:\Users\jp11cy\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\keras\_impl\keras\utils\__init__.py", line 34, in <module>
  File "C:\Users\jp11cy\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\keras\_impl\keras\utils\multi_gpu_utils.py", line 22, in <module>
    from tensorflow.python.keras._impl.keras.engine.training import Model
  File "C:\Users\jp11cy\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\keras\_impl\keras\engine\__init__.py", line 27, in <module>
  File "C:\Users\jp11cy\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\keras\_impl\keras\engine\training.py", line 30, in <module>
  File "C:\Users\jp11cy\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\keras\_impl\keras\engine\training_arrays.py", line 27, in <module>
  File "C:\Users\jp11cy\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\keras\_impl\keras\callbacks.py", line 37, in <module>
    from tensorflow.python.summary import summary as tf_summary
  File "C:\Users\jp11cy\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\summary\summary.py", line 62, in <module>
    from tensorflow.python.ops.summary_ops import tensor_summary
  File "C:\Users\jp11cy\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\ops\summary_ops.py", line 87, in <module>
    ops.NotDifferentiable("TensorSummary")
  File "C:\Users\jp11cy\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 2456, in NotDifferentiable
    _gradient_registry.register(None, op_type)
  File "C:\Users\jp11cy\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\registry.py", line 67, in register
    stack = traceback.extract_stack()
  File "C:\Users\jp11cy\AppData\Local\Programs\Python\Python36\lib\traceback.py", line 207, in extract_stack
    stack = StackSummary.extract(walk_stack(f), limit=limit)
  File "C:\Users\jp11cy\AppData\Local\Programs\Python\Python36\lib\traceback.py", line 358, in extract
    f.line
  File "C:\Users\jp11cy\AppData\Local\Programs\Python\Python36\lib\traceback.py", line 282, in line
    self._line = linecache.getline(self.filename, self.lineno).strip()
  File "C:\Users\jp11cy\AppData\Local\Programs\Python\Python36\lib\linecache.py", line 16, in getline
    lines = getlines(filename, module_globals)
  File "C:\Users\jp11cy\AppData\Local\Programs\Python\Python36\lib\linecache.py", line 47, in getlines
    return updatecache(filename, module_globals)
  File "C:\Users\jp11cy\AppData\Local\Programs\Python\Python36\lib\linecache.py", line 136, in updatecache
    with tokenize.open(fullname) as fp:
  File "C:\Users\jp11cy\AppData\Local\Programs\Python\Python36\lib\tokenize.py", line 454, in open
    encoding, lines = detect_encoding(buffer.readline)
  File "C:\Users\jp11cy\AppData\Local\Programs\Python\Python36\lib\tokenize.py", line 431, in detect_encoding
    encoding = find_cookie(first)
  File "C:\Users\jp11cy\AppData\Local\Programs\Python\Python36\lib\tokenize.py", line 395, in find_cookie
    raise SyntaxError(msg)
SyntaxError: invalid or missing encoding declaration for 'C:\\Users\\jp11cy\\AppData\\Local\\Programs\\Python\\Python36\\lib\\site-packages\\tensorflow\\python\\keras\\_impl\\keras\\utils\\__init__.py'

1 个答案:

答案 0 :(得分:1)

通过重新安装Tensorflow解决了问题。