Web.py - 属性错误:“模块”对象没有属性“application”;
我使用 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(
PS:The web.py版本是0.35。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您遇到了名称冲突。您将包命名为 web,并尝试导入模块 web。
我假设这是在一个包裹里?
\webpy\web\mysite.py
如果是这样,当您
导入 web
时,您导入的是您的包,而不是实际的 web.py。重命名它,或者重新排序你的 pythonpath。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.根据上面用户的建议,我已将我的评论变成了答案以提高其可见性:
如果您首先通过调用文件
web.py
而不是code.py
正如在 Python 教程中一样,您可能还会在您正在编码的文件夹中创建一个web.pyc
“字节代码”文件。发现名称冲突后,请确保同时删除web.pyc
文件。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 thancode.py
as in the Python tutorial, you might also have aweb.pyc
"byte code" file created in the folder where you are coding. After discovering the name collision, make sure you also delete theweb.pyc
file.这在我的情况下有效:在 app.yaml 文件中,替换
为此,
这解决了名称冲突。
This worked in my case: in the app.yaml file, replace
for this,
This solve the name conflict.
检查当前目录是否有web.py或web.pyc文件
Check that the current directory has web.py, or web.pyc files