尝试导入tensorflow时出现了“超出顶级程序包的导入”

时间:2019-11-27 11:06:06

标签: tensorflow keras

我在RBPi 3上新安装了Raspbian。我已经使用pip3(版本:tensorflow-1.8.0-cp35-none-linux_armv7l.whl)安装了Tenorflow,但是当我尝试从python IDLE导入它时Raspbian随附的3个)我收到此错误:

from .....third_party import wrapt
ValueError: attempted relative import beyond top-level package

尝试导入Keras时出现了相同的错误,但是大概是因为它首先没有导入TF。

以下是我成功安装并导入的软件包:

Cpython scipy scikit-learn pandas matplotlib

注意:我没有设置virtualenv,而是直接在父路径:home / pi上工作

编辑: 完整追溯

>>> import tensorflow
/home/pi/tensorflow/python/framework/dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/home/pi/tensorflow/python/framework/dtypes.py:517: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/home/pi/tensorflow/python/framework/dtypes.py:518: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/home/pi/tensorflow/python/framework/dtypes.py:519: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/home/pi/tensorflow/python/framework/dtypes.py:520: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/home/pi/tensorflow/python/framework/dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
/usr/lib/python3.5/importlib/_bootstrap.py:222: RuntimeWarning: compiletime version 3.4 of module 'tensorflow.python.framework.fast_tensor_util' does not match runtime version 3.5
  return f(*args, **kwds)
/usr/lib/python3.5/importlib/_bootstrap.py:222: RuntimeWarning: builtins.type size changed, may indicate binary incompatibility. Expected 432, got 412
  return f(*args, **kwds)
Traceback (most recent call last):
  File "/home/pi/tensorflow/python/training/tracking/data_structures.py", line 27, in <module>
    import wrapt
ImportError: No module named 'wrapt'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/tensorflow/__init__.py", line 28, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "/home/pi/tensorflow/python/__init__.py", line 73, in <module>
    from tensorflow.python.ops.standard_ops import *
  File "/home/pi/tensorflow/python/ops/standard_ops.py", line 25, in <module>
    from tensorflow.python import autograph
  File "/home/pi/tensorflow/python/autograph/__init__.py", line 35, in <module>
    from tensorflow.python.autograph import operators
  File "/home/pi/tensorflow/python/autograph/operators/__init__.py", line 40, in <module>
    from tensorflow.python.autograph.operators.control_flow import for_stmt
  File "/home/pi/tensorflow/python/autograph/operators/control_flow.py", line 24, in <module>
    from tensorflow.python.data.experimental.ops import scan_ops
  File "/home/pi/tensorflow/python/data/__init__.py", line 25, in <module>
    from tensorflow.python.data import experimental
  File "/home/pi/tensorflow/python/data/experimental/__init__.py", line 90, in <module>
    from tensorflow.python.data.experimental.ops.batching import dense_to_sparse_batch
  File "/home/pi/tensorflow/python/data/experimental/ops/batching.py", line 20, in <module>
    from tensorflow.python.data.ops import dataset_ops
  File "/home/pi/tensorflow/python/data/ops/dataset_ops.py", line 67, in <module>
    from tensorflow.python.training.tracking import tracking
  File "/home/pi/tensorflow/python/training/tracking/tracking.py", line 28, in <module>
    from tensorflow.python.training.tracking import data_structures
  File "/home/pi/tensorflow/python/training/tracking/data_structures.py", line 30, in <module>
    from .....third_party import wrapt
ValueError: attempted relative import beyond top-level package

1 个答案:

答案 0 :(得分:0)

通过@ {Matias Valdenegro

  

如果使用pip进行安装,则不应有一个名为   您的主文件夹中的tensorflow,它可能会干扰您的   tensorflow安装

我从主文件夹中删除了该tensorflow文件夹,如@ Matias Valdenegro所述,它干扰了标准安装,我删除了它并解决了。

我建议每次尝试在Raspberry Pi上安装Tensorflow时,都应仔细清理不完整/不成功的尝试。