导入tensorflow时出错

时间:2016-12-09 13:47:12

标签: python tensorflow

我在Ubuntu 16.04上导入tensorflow v0.12时遇到此错误。

cortana@cortana:~$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcurand.so locally
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 63, in <module>
    from tensorflow.core.framework.graph_pb2 import *
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/graph_pb2.py", line 16, in <module>
    from tensorflow.core.framework import node_def_pb2 as tensorflow_dot_core_dot_framework_dot_node__def__pb2
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/node_def_pb2.py", line 16, in <module>
    from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/attr_value_pb2.py", line 16, in <module>
    from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/tensor_pb2.py", line 16, in <module>
    from tensorflow.core.framework import resource_handle_pb2 as tensorflow_dot_core_dot_framework_dot_resource__handle__pb2
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/resource_handle_pb2.py", line 22, in <module>
    serialized_pb=_b('\n/tensorflow/core/framework/resource_handle.proto\x12\ntensorflow\"m\n\x0eResourceHandle\x12\x0e\n\x06\x64\x65vice\x18\x01 \x01(\t\x12\x11\n\tcontainer\x18\x02 \x01(\t\x12\x0c\n\x04name\x18\x03 \x01(\t\x12\x11\n\thash_code\x18\x04 \x01(\x04\x12\x17\n\x0fmaybe_type_name\x18\x05 \x01(\tB4\n\x18org.tensorflow.frameworkB\x13ResourceHandleProtoP\x01\xf8\x01\x01\x62\x06proto3')
TypeError: __init__() got an unexpected keyword argument 'syntax'

阅读其他类似的问题,我删除了protobuf和tensorflow并再次安装。我仍然有这些错误。我现在该怎么办?

Protobuf:&#39; 3.1.0&#39;
张量流量:r0.12
CUDA:8.0.44

2 个答案:

答案 0 :(得分:2)

这是因为protobuf版本冲突:对我来说,我从apt-get软件包管理器安装了python-protobuf v2.6.1并且在安装tensorflow时从pip manager安装了protobuf v3.3.0

从aptitude检查protobuf的版本

pip show protobuf

从pip

检查protobuf的版本
sudo pip uninstall protobuf
sudo apt-get remove python-protobuf

所以我卸下了两个:

sudo pip install protobuf

使用pip重新安装,它解决了问题!!!

@api.multi
def get_supplier_code(self):
    product_supplier_info_obj=self.env['product.supplierinfo']
    for line in self:        
        purchase_order=line.order_id
        supplier_info=product_supplier_info_obj.search([('product_tmpl_id','=',line.product_id.product_tmpl_id.id),('name','=',purchase_order.partner_id.id)],limit=1)
        line.product_code=supplier_info.product_code    

product_code=fields.Char(compute="get_supplier_code",store=False,string="purchase Code")

希望这会有所帮助..

答案 1 :(得分:-1)

键入sudo pip uninstall protobuf卸载sudo pip install protobuf,然后输入MicrosoftDateFormat重新安装 问题来自github https://github.com/tensorflow/tensorflow/issues/5168