1 問題描述
進入python3,import tensorflow後,終端報錯:
TypeError: _ _ new _ _() got an unexpected keyword argument ‘serialized_options’
2 原因分析
protobuf與tensorflow版本不匹配問題,網上大家給出了幾種解決方法:
- 使用命令:
pip install -U protobuf
- 將protobuf更新到3.6以上
- 降級到與tensorflow相匹配的版本
我嘗試了上述三種方法,都沒能成功,最後發現直接卸載protobuf再重新安裝就能解決問題。
3 解決方法
sudo pip3 uninstall protobuf
sudo pip3 install -U protobuf
4 驗證
進入python3:
import tensorflow as tf
a = tf.constant([1.0, 2.0], name = "a")
b = tf.constant([2.0, 3.0], name = "b")
result = a + b
sess = tf.Session()
sess.run(result)
問題解決: