简体   繁体   中英

ImportError: cannot import name '_assert_shallow_structure' from 'tree'

I am getting that error while importing tensorflow_probability in IDLE(Default python editor). I don't get that error if use same code in VS code. Works perfectly fine in VS code. Here are my imports

import numpy as np
import tensorflow.compat.v1 as tf
import tensorflow_probability as tfp
tf.disable_v2_behavior()

Here is complete error

    Traceback (most recent call last):
  File "C:\Python Scripts\pos_tagging.py", line 4, in <module>
    import tensorflow_probability as tfp
  File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\__init__.py", line 77, in <module>
    from tensorflow_probability.python import *  # pylint: disable=wildcard-import
  File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\python\__init__.py", line 21, in <module>
    from tensorflow_probability.python import bijectors
  File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\python\bijectors\__init__.py", line 23, in <module>
    from tensorflow_probability.python.bijectors.absolute_value import AbsoluteValue
  File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\python\bijectors\absolute_value.py", line 23, in <module>
    from tensorflow_probability.python.bijectors import bijector
  File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\python\bijectors\bijector.py", line 31, in <module>
    from tensorflow_probability.python.internal import distribution_util
  File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\python\internal\distribution_util.py", line 28, in <module>
    from tensorflow_probability.python.internal import prefer_static
  File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\python\internal\prefer_static.py", line 30, in <module>
    from tensorflow_probability.python.internal.backend import numpy as nptf
  File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\python\internal\backend\numpy\__init__.py", line 21, in <module>
    from tensorflow_probability.python.internal.backend.numpy import bitwise
  File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\python\internal\backend\numpy\bitwise.py", line 23, in <module>
    from tensorflow_probability.python.internal.backend.numpy import _utils as utils
  File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\python\internal\backend\numpy\_utils.py", line 26, in <module>
    from tensorflow_probability.python.internal.backend.numpy import nest
  File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\python\internal\backend\numpy\nest.py", line 34, in <module>
    from tree import _assert_shallow_structure
ImportError: cannot import name '_assert_shallow_structure' from 'tree' (C:\Users\aaaa\AppData\Local\Programs\Python\Python38\Lib\idlelib\tree.py)

Python Version:3.8.5 64 bit Windows machine

Look at where it's importing from (C:\\Users\\aaaa\\AppData\\Local\\Programs\\Python\\Python38\\Lib\\idlelib\\tree.py) I think you meant to import from dm-tree.

Here's my solution: if you don't have dm-tree installed

pip install dm-tree

if you do, install PyCharm and use that to run the code. It wont have the conflict that IDLE would on the tree.py

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM