无法导入Tensorflow_probability

cyvaqqii  于 2022-12-04  发布在  其他
关注(0)|答案(3)|浏览(225)

当我尝试import tensorflow_probability时,我得到这个错误:

Traceback (most recent call last):
  File "PATH", line 1, in <module>
    import tensorflow_probability
  File "PATH", line 75, in <module>
    from tensorflow_probability.python import *  # pylint: disable=wildcard-import
  File "PATH", line 24, in <module>
    from tensorflow_probability.python import edward2
  File "PATH", line 32, in <module>
    from tensorflow_probability.python.experimental.edward2.generated_random_variables import *
  File "PATH", line 34, in <module>
    from tensorflow_probability.python.experimental import auto_batching
  File "PATH", line 24, in <module>
    from tensorflow_probability.python.experimental.auto_batching import frontend
  File "PATH", line 46, in <module>
    from tensorflow.python.autograph.pyct import compiler
ImportError: cannot import name 'compiler' from 'tensorflow.python.autograph.pyct' (PATH)

我不知道为什么Python不能导入这个模块,因为当我在cmd中输入pip list时,它告诉我我已经安装了tensorflow-probability 0.8.0rc0

jum4pzuy

jum4pzuy1#

尝试安装tf_agents包。我在尝试导入tensorflow_probability时出现了一些导入错误。这些错误包括:

  • module 'tensorflow.python.ops.linalg.linear_operator' has no attribute 'make_composite_tensor'
  • cannot import name 'all_util' from 'tensorflow_probability.python.internal' .

这些问题在我安装和导入tf_agents时得到了解决。

pip install --upgrade tf_agents

如果使用jupyter,请将以下代码添加到单元格中,然后运行它:

import sys
!{sys.executable} -m pip install --upgrade tf_agents
hc2pp10m

hc2pp10m2#

我试过在Google colabUbuntu 18版本中导入。在colab中它直接工作,在ubuntu中我遇到了问题。
升级到最新的pip和TensorFlow版本解决了我的问题。

科拉布:

import tensorflow_probability as tfp

Ubuntu第18版:

升级pip

pip install --upgrade pip

安装最新版本的TensorFlow

pip install tensorflow

安装tensorflow _概率

pip install --upgrade tensorflow-probability

tensorflow 概率版本0.11.1

juzqafwq

juzqafwq3#

有完全相同的问题。删除旧的tensorflow版本和每晚安装一切解决了我的问题

pip uninstall tensorflow
pip uninstall tensorflow-probability

pip install tf-nightly
pip install tfp-nightly

相关问题