AttributeError: 模块“tensorflow.python.training.checkpointable"没有属性“CheckpointableBase" [英] AttributeError: module 'tensorflow.python.training.checkpointable' has no attribute 'CheckpointableBase'

查看:16
本文介绍了AttributeError: 模块“tensorflow.python.training.checkpointable"没有属性“CheckpointableBase"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直致力于学习人工智能以及如何使用 Python 进行编码.我正在做一个项目,我决定更新一些 Python 包,这些包不是新的,然后发生了一些事情,我无法编译我的代码.我删除了 Anaconda3 并重新设置,但没有用.我一直看到我写的这个问题作为一个主题.如果有人帮助我,我会很高兴得到一些帮助.

<预><代码>>>>将张量流导入为 tf文件C:UsersAliGalipAnaconda3Yenilibsite-packages ensorflow\__init__.py",第 24 行,在 <module>from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import文件C:UsersAliGalipAnaconda3Yenilibsite-packages ensorflowpython\__init__.py",第63行,在<module>from tensorflow.python.framework.framework_lib import * # pylint: disable=redefined-builtin文件C:UsersAliGalipAnaconda3Yenilibsite-packages ensorflowpythonframeworkframework_lib.py",第104行,在<module>从 tensorflow.python.framework.importer 导入 import_graph_def文件C:UsersAliGalipAnaconda3Yenilibsite-packages ensorflowpythonframeworkimporter.py",第32行,在<module>从 tensorflow.python.framework 导入函数文件C:UsersAliGalipAnaconda3Yenilibsite-packages ensorflowpythonframeworkfunction.py",第36行,在<module>从 tensorflow.python.ops 导入 resource_variable_ops文件C:UsersAliGalipAnaconda3Yenilibsite-packages ensorflowpythonops esource_variable_ops.py",第35行,在<module>从 tensorflow.python.ops 导入变量文件C:UsersAliGalipAnaconda3Yenilibsite-packages ensorflowpythonopsvariables.py",第 40 行,在 <module>类变量(checkpointable.CheckpointableBase):AttributeError: 模块tensorflow.python.training.checkpointable"没有属性CheckpointableBase"

解决方案

同样的问题已经作为 GitHub 问题发布.特别是,@allanlavoie 建议的 解决方案 在这里很可能是相关的嗯:

<块引用>

听起来像是 TensorFlow 的半更新版本.您能否尝试完全删除 TensorFlow(例如 pip uninstall tf-nightly 或安装的任何软件包),确保 import tensorflow 失败,然后重新安装?

由于从您的问题中可以看出您正在使用 Anaconda 来管理您的 Python 环境,如果上述方法无法解决您的问题,您可以尝试在干净的 conda 环境中安装 TensorFlow,如下所示:

  1. 通过conda create --name tftest 创建一个新环境.(您可以将 tftest 替换为例如您当前项目的名称.)
  2. 通过 activate tftest(或 source activate tftest 如果您碰巧使用 MSYS2 的 bash 或类似的东西)激活新环境.
  3. 通过conda install tensorflow将TF安装到这个环境中.
  4. 通过 where python(应该生成包含tftest"的路径)确保您处于正确的环境中.
  5. 通过python运行Python.
  6. 在该环境的 shell 中将 tensorflow 导入为 tf.

由于您使用的是 PyCharm(请参阅此答案的注释),因此您需要设置 PyCharm 以使用此新环境.事实上,为每个项目使用一个新环境虽然会占用大量磁盘空间,但却是避免这些依赖程度较高的数值包的依赖问题的好方法.

I've been working on learning artificial intelligence and how to code with Python.I was working on a project and I decided to update some packages of Python which were not new to work on then something happened and I can't compile my codes.I deleted Anaconda3 and set it up again but not worked. I've been seeing this problem which I wrote as a topic.If someone helps me,I would be appriciated to get some help.

>>> import tensorflow as tf
  File "C:UsersAliGalipAnaconda3Yenilibsite-packages	ensorflow\__init__.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "C:UsersAliGalipAnaconda3Yenilibsite-packages	ensorflowpython\__init__.py", line 63, in <module>
    from tensorflow.python.framework.framework_lib import *  # pylint: disable=redefined-builtin
  File "C:UsersAliGalipAnaconda3Yenilibsite-packages	ensorflowpythonframeworkframework_lib.py", line 104, in <module>
    from tensorflow.python.framework.importer import import_graph_def
  File "C:UsersAliGalipAnaconda3Yenilibsite-packages	ensorflowpythonframeworkimporter.py", line 32, in <module>
    from tensorflow.python.framework import function
  File "C:UsersAliGalipAnaconda3Yenilibsite-packages	ensorflowpythonframeworkfunction.py", line 36, in <module>
    from tensorflow.python.ops import resource_variable_ops
  File "C:UsersAliGalipAnaconda3Yenilibsite-packages	ensorflowpythonops
esource_variable_ops.py", line 35, in <module>
    from tensorflow.python.ops import variables
  File "C:UsersAliGalipAnaconda3Yenilibsite-packages	ensorflowpythonopsvariables.py", line 40, in <module>
    class Variable(checkpointable.CheckpointableBase):
AttributeError: module 'tensorflow.python.training.checkpointable' has no attribute 'CheckpointableBase'

解决方案

The same question has been posted as a GitHub issue. In particular, the solution suggested by @allanlavoie is likely relevant here as well:

Sounds like a half-updated version of TensorFlow. Could you try removing TensorFlow entirely (e.g. pip uninstall tf-nightly or whichever package is installed), making sure import tensorflow fails, then reinstalling?

Since it is apparent from your question that you're using Anaconda to manage your Python environments, if the above fails to solve your problem, you can try to install TensorFlow in a clean conda environment as follows:

  1. Create a new environment through conda create --name tftest. (You can replace tftest with e.g. the name of your current project.)
  2. Activate that new environment through activate tftest (or source activate tftest if you happen to be using MSYS2's bash, or something similar to that).
  3. Install TF into this environment through conda install tensorflow.
  4. Ensure that you're in the right environment through where python (which should produce a path containing "tftest").
  5. Run Python through python.
  6. import tensorflow as tf in a shell in that environment.

Since you are using PyCharm (cf. the comments for this answer), you will then want to set up PyCharm for using this new environment instead. Indeed, using a new environment for every project, while disk space-intensive, is a good way of avoiding dependency issues for these rather dependency-heavy numerical packages.

这篇关于AttributeError: 模块“tensorflow.python.training.checkpointable"没有属性“CheckpointableBase"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆