繁体   English   中英

Python和Peewee中的AttributeError

[英]AttributeError in Python and Peewee

我对Python和Peewee还是很陌生。

我有一个真正简单的脚本设置,该脚本给我错误AttributeError: 'module' object has no attribute 'Model' Model'-有人可以告诉我为什么吗?

我有以下脚本:

import peewee
from peewee import *

print dir(peewee)

class User(peewee.Model):
    username = peewee.CharField()
  • 我已经尝试使用peewee.ModelModel来创建User类,因为我之前发现了一个类似错误的问题,该问题可能是问题所在,但似乎不是我的问题案件。 仅使用Model时出现另一个错误( NameError: name 'Model' is not defined

  • 我已经把我的peewee更新到了最新版本( sudo pip intall -U peewee

  • 我试图运行一个print dir(peewee) ,该print dir(peewee)为我提供['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'peewee'] 我觉得这有点奇怪,因为导入数学然后dir(math)给了我数学功能。

完整的堆栈是

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

我正在运行peewee版本2.2.4和Python版本2.7.3

我在http://peewee.readthedocs.org/en/latest/peewee/cookbook.html找到了脚本

您已将文件命名为"/home/ubuntu/python/test/peewee.py"因此Python尝试从中导入而不是peewee模块。

不要使用与Python模块名称相同的文件名。 只需将您的"/home/ubuntu/python/test/peewee.py"文件重命名为其他文件即可。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM