来自源主服务器的Tensorflow会从导入中提供语法错误

时间:2016-07-29 04:24:03

标签: tensorflow python-3.5 ubuntu-16.04

我尝试从源(主)编译tensorflow,并使用python3而不是python2pip默认为pip3)关注tensorflow instructions。在测试第一个模型之前,我可以完成所有步骤。

我注意到通过简单的import tensorflow可以最小化地重现问题。错误如下:

$ python3
Python 3.5.2 (default, Jul  5 2016, 12:43:10) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcurand.so locally
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/__init__.py", line 23, in <module>
    from tensorflow.python import *
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/__init__.py", line 65, in <module>
    import tensorflow.contrib as contrib
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/__init__.py", line 30, in <module>
    from tensorflow.contrib import learn
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/learn/__init__.py", line 72, in <module>
    from tensorflow.contrib.learn.python.learn import *
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/learn/python/__init__.py", line 23, in <module>
    from tensorflow.contrib.learn.python.learn import *
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/learn/python/learn/__init__.py", line 26, in <module>
    from tensorflow.contrib.learn.python.learn import estimators
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/learn/python/learn/estimators/__init__.py", line 23, in <module>
    from tensorflow.contrib.learn.python.learn.estimators.autoencoder import TensorFlowDNNAutoencoder
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/learn/python/learn/estimators/autoencoder.py", line 25, in <module>
    from tensorflow.contrib.learn.python.learn.estimators.base import TensorFlowBaseTransformer
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/learn/python/learn/estimators/base.py", line 34, in <module>
    from tensorflow.contrib.learn.python.learn.estimators import estimator
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 39, in <module>
    from tensorflow.contrib.learn.python.learn.learn_io import data_feeder
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/learn/python/learn/learn_io/__init__.py", line 22, in <module>
    from tensorflow.contrib.learn.python.learn.learn_io.dask_io import extract_dask_data
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/learn/python/learn/learn_io/dask_io.py", line 26, in <module>
    import dask.dataframe as dd
  File "/usr/local/lib/python3.5/dist-packages/dask/__init__.py", line 7, in <module>
    from .delayed import do, delayed, value
  File "/usr/local/lib/python3.5/dist-packages/dask/delayed.py", line 12, in <module>
    from . import base
  File "/usr/local/lib/python3.5/dist-packages/dask/base.py", line 287, in <module>
    import pandas as pd
  File "/usr/local/lib/python3.5/dist-packages/pandas/__init__.py", line 22, in <module>
    from pandas.compat.numpy import *
  File "/usr/local/lib/python3.5/dist-packages/pandas/compat/__init__.py", line 350, in <module>
    from dateutil import parser as _date_parser
  File "/usr/local/lib/python3.5/dist-packages/dateutil/parser.py", line 158
    l.append("%s=%s" % (attr, `value`))
                              ^
SyntaxError: invalid syntax
与类似语法问题相关的

Other questions与旧版protobuf相关,但我的版本为3

$ pip3 show protobuf
---
Metadata-Version: 2.0
Name: protobuf
Version: 3.0.0b2
Summary: Protocol Buffers
Home-page: https://developers.google.com/protocol-buffers/
Author: protobuf@googlegroups.com
Author-email: protobuf@googlegroups.com
Installer: pip
License: New BSD License
Location: /usr/local/lib/python3.5/dist-packages
Requires: six, setuptools
Classifiers:
  Programming Language :: Python
  Programming Language :: Python :: 2
  Programming Language :: Python :: 2.6
  Programming Language :: Python :: 2.7
  Programming Language :: Python :: 3
  Programming Language :: Python :: 3.3
  Programming Language :: Python :: 3.4

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:6)

看起来安装的dateutil包(TensorFlow依赖于daskpandas)与Python 3不兼容,使用反引号作为repr()的同义词,在3.0中被删除。发生错误的dateutil/parser.py中的特定行在2011年为updated for Python 3

尝试运行以下命令升级dateutil

$ pip3 install python-dateutil --upgrade