Reputation: 957
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?
Upvotes: 3
Views: 1906
Reputation: 11
This problem appears in vscode But it does not appear in pycharm Replace the total include-me-library with include-each-item alone
Upvotes: -2
Reputation: 957
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'
Upvotes: 4