python - 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 :)
解决方案
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 包。许多初学者犯的非常棘手的错误:)
推荐阅读
- javascript - 浏览器如何知道我的鼠标光标指向哪个元素?
- c# - 使用 ADFS 授权对 ASP.NET Core 2.1 应用程序的请求
- javascript - AIO指纹如何使用?
- javascript - TSconfig:为每个ts文件夹编译一个新的js文件夹
- python - 如何在python中打印带有阿拉伯字符的日期
- php - 您如何从 AJAX 调用中的类访问 wordpress 建立的短代码属性?
- c++ - 如何使用 CMAKE 将 FFTW 添加到 Android 项目
- python - 使用opencv在另一个图像中查找相似图像
- asp.net-mvc-4 - 具有基本身份验证的应用程序在本地主机上工作,但在 IIS 上发布后获得未经授权的用户
- scroll - goto 功能与 sapper-noscroll