Web.py - AttributeError:'module'对象没有属性'application'

时间:2011-06-20 14:03:41

标签: python google-app-engine web.py

我使用web.py写小helloworld网站,但是当我运行python code.py时收到错误消息:

Traceback (most recent call last):   File "E:\Python25\webpy\web\mysite.py", line 1, in <module>
    import web   File "E:\Python25\webpy\web\web.py", line 4, in <module>
    app = web.application(urls, globals()) AttributeError: 'module' object has no attribute 'application'

这是我的代码(从web.py的教程粘贴):

import web

urls = ( '/','Index',
)

class Index:
  def GET(self):
    return "Hello,world!"

app=web.application(urls,globals())

if __name__=="__main__":
  app.run(

P.S:web.py版本是0.35。

4 个答案:

答案 0 :(得分:9)

您正在遇到名称冲突。您将包名称为web,并且正在尝试导入模块Web。

我假设这是一个包裹?

\webpy\web\mysite.py

如果是import web,那么您导入您的包而不是实际的web.py.重命名它,或重新排序你的pythonpath。

答案 1 :(得分:1)

这适用于我的情况:在 app.yaml 文件中,替换

- url: /.*
  script: test.application

为此,

- url: /.*
  script: test.app

这解决了名称冲突。

答案 2 :(得分:1)

Per recommendation from a user above, I have turned my comment into an answer to improve its visibility:

If you first started by calling your file web.py, rather than code.py as in the Python tutorial, you might also have a web.pyc "byte code" file created in the folder where you are coding. After discovering the name collision, make sure you also delete the web.pyc file.

答案 3 :(得分:0)

检查当前目录中是否包含web.py或web.pyc文件