首页 > 解决方案 > Cannot import name 'TinyDB'

问题描述

I installed tinydb with pip. pip install tinydb I also tried it with pip3

I used the example code of tinydb to test it.

from tinydb import TinyDB, Query
db = TinyDB('test.json')
db.insert({'int': 1, 'char': 'a'})
db.insert({'int': 1, 'char': 'b'})

but I get the importError

Traceback (most recent call last):
  File "tinydb.py", line 1, in <module>
    from tinydb import TinyDB, Query
  File "/home/janw/Desktop/tinydb.py", line 1, in <module>
    from tinydb import TinyDB, Query
ImportError: cannot import name 'TinyDB'

Thanks for any help :)

标签: pythontinydb

解决方案


Traceback (most recent call last):
  File "tinydb.py", line 1, in <module>
    from tinydb import TinyDB, Query
  File "/home/janw/Desktop/tinydb.py", line 1, in <module>

如果您将文件命名为 tinydb.py,则 python 将无法找到实际的 TinyDB 包。许多初学者犯的非常棘手的错误:)


推荐阅读