0

i'm currently facing an issue with importing the tinyDB python package into python.

These are the steps I did to install tinyDB in raspbian. 1. Running the command: sudo pip3 install tinydb

Output says: Requirement already satisfied (use --upgrade to upgrade): tinydb in /usr/local/lib/python3.4/dist-packages

Which means the tinydb package has been installed successfully and setup.py is installed.

This is the code i did in python to import tinydb.

Code:

    from tinydb import TinyDB, Query

    db = TinyDB('/home/pi/Desktop/book/book.json')
    table = db.table('name')
    table.insert({'value': True})
    table.all()
    [{'value': True}]

However, when importing tinydb into python, it gives this error: ImportError: cannot import name 'TinyDB'

Update:

Fixed the module not found error but having another error right now. Error:

Traceback (most recent call last):
File "/home/pi/mp/mp.py", line 4, in <module>
db = TinyDB('/home/pi/Desktop/csv/book.json')
File "/usr/local/lib/python3.4/dist-packages/tinydb/database.py", line    93, in __init__
self._table = self.table(table)
File "/usr/local/lib/python3.4/dist-packages/tinydb/database.py", line  110, in table
table = self.table_class(StorageProxy(self._storage, name), **options)
File "/usr/local/lib/python3.4/dist-packages/tinydb/database.py", line  202, in __init__
data = self._read()
File "/usr/local/lib/python3.4/dist-packages/tinydb/database.py", line 277, in _read
return self._storage.read()
File "/usr/local/lib/python3.4/dist-packages/tinydb/database.py", line 31, in read
raw_data = (self._storage.read() or {})[self._table_name]
File "/usr/local/lib/python3.4/dist-packages/tinydb/storages.py", line 105, in read
return json.load(self._handle)
File "/usr/lib/python3.4/json/__init__.py", line 268, in load
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File "/usr/lib/python3.4/json/__init__.py", line 318, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.4/json/decoder.py", line 346, in decode
raise ValueError(errmsg("Extra data", s, end, len(s)))
ValueError: Extra data: line 7 column 1 - line 73 column 1 (char 212 -  2423)
JasonSmith
  • 27
  • 1
  • 7
  • How are you running your script? Perhaps you're using another python version / installation? – Ilja Everilä May 31 '17 at 08:19
  • @IljaEverilä we're running it in python3 – JasonSmith May 31 '17 at 08:31
  • What does `which python3` show you? `/usr/local/bin/python3` or something else? – Ilja Everilä May 31 '17 at 08:33
  • im using python 3.4.2. it just says: Traceback (most recent call last): File "/home/pi/mp/tinydb.py", line 1, in from tinydb import TinyDB, Query File "/home/pi/mp/tinydb.py", line 1, in from tinydb import TinyDB, Query ImportError: cannot import name 'TinyDB' – JasonSmith May 31 '17 at 08:45
  • Ah. That traceback gives it away: you've named your file `tinydb.py`, so when you try to `from tinydb import ...` it is trying to import from your own module. Rename the file and all should be well. – Ilja Everilä May 31 '17 at 08:53
  • Btw this is the reason why you should always include the **full traceback** in questions. – Ilja Everilä May 31 '17 at 08:59
  • thank you, i managed to fix the module not found error. However, im facing another error. I cant paste it here because it exceed the character limit. I will update the error above – JasonSmith May 31 '17 at 08:59
  • It's bad style to use the same question as a generic debugging forum. You asked a single question and got an answer (in the comments). You should create a new question, if you have new issues. Your current issue seems to be that `smartkey.json` is not valid JSON. – Ilja Everilä May 31 '17 at 09:08

0 Answers0