I'm quite new to Python and thus also Peewee.
I have a real simple script set up that gives me the error AttributeError: 'module' object has no attribute 'Model'
- Can anyone tell me why?
I've got the following script:
import peewee
from peewee import *
print dir(peewee)
class User(peewee.Model):
username = peewee.CharField()
I've tried to make the User class with both peewee.Model
and just Model
, as I've found some previous question about a similar error, that stated that it could be the problem, but it doesn't seem to be in my case. I get another error (NameError: name 'Model' is not defined
) when only using Model
I have updated my peewee to newest version (sudo pip intall -U peewee
)
print dir(peewee)
which gives me ['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'peewee']
. I find this a bit odd, since a import math and then dir(math) gives me the functions of math.The full stack is
Traceback (most recent call last):
File "peewee.py", line 1, in <module>
import peewee
File "/home/ubuntu/python/test/peewee.py", line 6, in <module>
class User(Model):
NameError: name 'Model' is not defined
I'm running peewee version 2.2.4 and Python version 2.7.3
I found the script at http://peewee.readthedocs.org/en/latest/peewee/cookbook.html
You have named your file "/home/ubuntu/python/test/peewee.py"
so Python is trying to import from that instead of the peewee
module.
Don't use file names that mirror the names of your Python modules. Just rename your "/home/ubuntu/python/test/peewee.py"
file to something else and it will work.