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

Xhinking picture Xhinking · Jun 20, 2011 · Viewed 11.6k times · Source

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:\Python25\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.

Answer

Nix picture Nix · Jun 20, 2011

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.