开发者

Web.py - AttributeError: 'module' object has no attribute 'application'

I use web.py write small helloworld site,but when I run python code.py I get an error message:

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

Here is my code(paste from web.py's tutorials):

import web

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

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

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

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

P.S:The web.py version is 0.35.


You are runing into name collisions. You named your package web, and are trying to import a module web.

I am assuming this is in a package?

\webpy\web\mysite.py

If so when you do import web you are importing your package not the actual web.py. Rename it, or reorder your pythonpath.


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.


This worked in my case: in the app.yaml file, replace

- url: /.*
  script: test.application

for this,

- url: /.*
  script: test.app

This solve the name conflict.


Check that the current directory has web.py, or web.pyc files

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜