3

OS Linux Mint 18.3 (but same problem also with version 19)
Python3 and Sqlite3 installed

After a lot of trouble with "pip / pip3", I managed to install Peewee.

I tried running the following sample script with python3 peewee.py but I get this error:

SCRIPT (peewee.py)

from peewee import *

db = SqliteDatabase("people.db")

class Person(Model):
    name = CharField()
    birthday = DateField()

    class Meta:
        database = db # This model uses the "people.db" database.

class Pet(Model):
    owner = ForeignKeyField(Person, backref='pets')
    name = CharField()
    animal_type = CharField()

    class Meta:
        database = db # this model uses the "people.db" database

db.connect()

ERROR

Traceback (most recent call last):
  File "peewee.py", line 3, in <module>
    from peewee import *
  File "/home/.../peewee.py", line 6, in <module>
    db = SqliteDatabase("people.db")
NameError: name 'SqliteDatabase' is not defined

I've already done an extensive research on google / StackOverflow, but I can't solve this problem. Could you please help me?

Igor Carmagna
  • 957
  • 1
  • 10
  • 34

2 Answers2

4

I tried a different approach to the problem... Turns out the problem isn't related to peewee specifically but to python.

I named the script file peewee.py.

So, because of the first line of the script from peewee import *, Python imports my own script instead of the real peewee package, hence the error.

SOLUTION
Rename the script file to something else.

(Comment: ... So sad... a lot of time wasted for a silly newbie error)

Source:
Python AttributeError: 'module' object has no attribute 'connect'

Igor Carmagna
  • 957
  • 1
  • 10
  • 34
-2

This problem appears in vscode But it does not appear in pycharm Replace the total include-me-library with include-each-item alone

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 04 '23 at 22:12