ImportError:没有名为“backports”的模块

Posted

技术标签:

【中文标题】ImportError:没有名为“backports”的模块【英文标题】:ImportError: No module named 'backports' 【发布时间】:2017-11-19 00:34:16 【问题描述】:

在使用 tensorflow 安装再训练模型时,我运行了以下命令:

bazel-bin/tensorflow/examples/image_retraining/retrain --image_dir <..directory..>

错误:

ImportError: No module named 'backports'

Traceback (most recent call last):
  File "/home/nishith/tensorflow/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/examples/image_retraining/retrain.py", line 91, in <module>
    import tensorflow as tf
  File "/home/nishith/tensorflow/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/home/nishith/tensorflow/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/__init__.py", line 64, in <module>
    from tensorflow.python.framework.framework_lib import *
  File "/home/nishith/tensorflow/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/framework/framework_lib.py", line 100, in <module>
    from tensorflow.python.framework.subscribe import subscribe
  File "/home/nishith/tensorflow/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/framework/subscribe.py", line 26, in <module>
    from tensorflow.python.ops import variables
  File "/home/nishith/tensorflow/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/ops/variables.py", line 26, in <module>
    from tensorflow.python.ops import control_flow_ops
  File "/home/nishith/tensorflow/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/ops/control_flow_ops.py", line 70, in <module>
    from tensorflow.python.ops import tensor_array_ops
  File "/home/nishith/tensorflow/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/ops/tensor_array_ops.py", line 33, in <module>
    from tensorflow.python.util import tf_should_use
  File "/home/nishith/tensorflow/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/util/tf_should_use.py", line 28, in <module>
    from backports import weakref  # pylint: disable=g-bad-import-order
ImportError: No module named 'backports'

【问题讨论】:

我做了pip install backports.weakref,但还是有错误,最后发现是PYTHONPATH对应路径设置错误。 @Jecky 你是如何诊断和解决这个问题的? 【参考方案1】:

试试:

pip install backports.weakref

【讨论】:

以上是关于ImportError:没有名为“backports”的模块的主要内容,如果未能解决你的问题,请参考以下文章

ImportError:没有名为枚举的模块

ImportError:没有名为“appdirs”的模块

ImportError:没有名为 websocket 的模块

ImportError:没有名为“backports”的模块

ImportError:没有名为 ghostscript 的模块

ImportError:运行火花时没有名为请求的模块