简体   繁体   English

无法导入名称“TinyDB”

[英]Cannot import name 'TinyDB'

I installed tinydb with pip.我用 pip 安装了 tinydb。 pip install tinydb I also tried it with pip3 pip install tinydb我也用 pip3 试过

I used the example code of tinydb to test it.我使用 tinydb 的示例代码对其进行了测试。

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但我得到了 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:)谢谢你的帮助:)

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>

If you name your file tinydb.py then python will not be able to locate the actual TinyDB package.如果您将文件命名为 tinydb.py,则 python 将无法找到实际的 TinyDB package。 Very tricky mistake that a lot of beginners make:)很多初学者都会犯的非常棘手的错误:)

I installed it using pip install tinydb and it worked for me.我使用pip install tinydb安装了它,它对我有用。 I'm able to import and use TinyDB.我能够导入和使用 TinyDB。

Try removing it pip uninstall tinydb and installing it again.尝试删除它pip uninstall tinydb并重新安装。

If this doesn't work, try running pip install --upgrade tinydb .如果这不起作用,请尝试运行pip install --upgrade tinydb I hope this works.我希望这行得通。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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