首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python和Peewee中的AttributeError

Python和Peewee中的AttributeError
EN

Stack Overflow用户
提问于 2014-06-20 20:22:01
回答 1查看 1.6K关注 0票数 3

我对Python和Peewee都很陌生。

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

我有以下脚本:

代码语言:javascript
复制
import peewee
from peewee import *

print dir(peewee)

class User(peewee.Model):
    username = peewee.CharField()
  • 我尝试使用peewee.ModelModel来创建User类,因为我之前发现了一些关于类似错误的问题,这表明可能是问题所在,但在我的情况下似乎并非如此。如果只使用NameError: name 'Model' is not defined,则会得到另一个错误( Model )
  • 我已将我的peewee更新为最新版本(sudo pip intall -U peewee)。
  • 我试着运行一个print dir(peewee),这给了我['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'peewee']。我觉得这有点奇怪,因为一个重要的数学和dir(数学)给了我数学的功能。

整个堆栈是

代码语言:javascript
复制
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

我正在运行peeweeVersion2.2.4和PythonVersion2.7.3

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-20 20:35:52

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

不要使用反映Python模块名称的文件名。只要将您的"/home/ubuntu/python/test/peewee.py"文件重命名为其他文件,它就能工作了。

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24335071

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档