I'm trying to make a simple Hello World web page in Python 3.7.4 and web.py 0.40-dev1
(which is supposed to be compatible) and I'm running into
AttributeError: module 'web' has no attribute 'applications'
error. I've googled enough to know that is a name collision, but for the love of God I can't trace it.
Here's the full code:
import web
urls = (
'/', 'index'
)
application = web.applications(urls, globals())
class index:
def GET(self):
greeting = 'Hello world'
return greeting
if __name__ == "__main__":
application.run
And here's the full Python interpreter output:
Traceback (most recent call last):
File "bin\app.py", line 7, in <module>
application = web.applications(urls, globals())
AttributeError: module 'web' has no attribute 'applications'
Because of you I just install web.py
to test your code. It seems there is no applications
in the web.py
. If your want to check it just try the below example.
>>> import web
>>>
>>> `applications` in dir(web)
False
>>> `application` in dir(web)
True
So is should be web.application
. Your first problem be solved, when you run it you'll get another error RuntimeError: generator raised StopIteration
. That problem is solved in “RuntimeError: generator raised StopIteration” every time I try to run app question. It occurs because of python 3.7.*
versions. There is something wrong with 0.40-dev1
version. You have two opetions.
0.40-dev1
version and install the stable version from there master branch. Just uninstall by using this command pip uninstall web.py==0.40-dev1
and run this command pip install -e git+https://github.com/webpy/webpy.git#egg=webpy
. This will install the latest version from master branch. (This is worked for me)utils.py
in this way. Find it from from Python\Python37\Lib\site-packages\web\utils.py
(I try it from windows) and find the line 526
. Then you'll see something like thisyield next(seq)
and surround it with try-catch
statement in this way. (Not Recommended, instead of that make your own version by fork the relevant branch)def take(seq, n):
for i in range(n):
# yield next(seq)
try:
yield next(seq)
except StopIteration:
return
This will solved your problem. I added some extra context here because I want to see the output. I don't know much about this change, just took it from “RuntimeError: generator raised StopIteration” every time I try to run app question.