2

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

Kong Konfus
  • 57
  • 1
  • 5
  • Please be more specific what you did. Did you installed it in virtual environment or base environment. I tried to reproduce your code but it works fine at my end. – Jaskaran Singh Apr 04 '20 at 10:01
  • Hmm how could I explain. Like I start terminal and was on Desktop directory and installed it. And on my Desktop directory is also my py script. :/ – Kong Konfus Apr 04 '20 at 10:06
  • in terminal type python as well as python3 and try to import it. Do you have multiple versions of python installed try python and python3 to check versions – Jaskaran Singh Apr 04 '20 at 10:08
  • Thats strange when I use python 2 or 3 in terminal I can import it. Super strange – Kong Konfus Apr 04 '20 at 11:04
  • I tested on other device and it worked :/ – Kong Konfus Apr 04 '20 at 11:16

2 Answers2

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

Aditya Garg
  • 838
  • 6
  • 19
-2

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.

Gagan Deep Singh
  • 372
  • 3
  • 13