Cannot import name 'TinyDB'

Viewed 917

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 :)

2 Answers
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. Very tricky mistake that a lot of beginners make :)

I installed it using pip install tinydb and it worked for me. I'm able to import and use TinyDB.

Try removing it pip uninstall tinydb and installing it again.

If this doesn't work, try running pip install --upgrade tinydb. I hope this works.

Related