Forums

Web2py wsgi import error: name 'db' is not defined

I added a pip package to my virtual environment, after which I'm getting this error:

2025-01-19 17:18:23 ERROR:root:Error running WSGI application

2025-01-19 17:18:23 ERROR:root:NameError: name 'db' is not defined

2025-01-19 17:18:23 ERROR:root: File "/var/www/ghdev_pythonanywhere_com_wsgi.py", line 21, in <module>

2025-01-19 17:18:23 ERROR:root: from gluon.main import wsgibase as application

2025-01-19 17:18:23 ERROR:root:

2025-01-19 17:18:23 ERROR:root: File "/home/ghdev/web2py/gluon/main.py", line 113, in <module>

2025-01-19 17:18:23 ERROR:root: load_routes()

2025-01-19 17:18:23 ERROR:root:

2025-01-19 17:18:23 ERROR:root: File "/home/ghdev/web2py/gluon/rewrite.py", line 384, in load

2025-01-19 17:18:23 ERROR:root: exec(data, symbols)

2025-01-19 17:18:23 ERROR:root:

2025-01-19 17:18:23 ERROR:root: File "<string>", line 2, in <module>

as a result, I can't even reach the web2py admin login screen or any other functionality, except the Pythonanywhere dashboard screens. All of the code worked before the pip install.

Urgently need help. Thanks.

What was the package?

the package was aiohttp. I'm now seeing this error also:

2025-01-20 14:44:06,474: Error running WSGI application
2025-01-20 14:44:06,661: RuntimeError: web2py depends on pydal, which apparently you have not installed.
2025-01-20 14:44:06,662: Probably you cloned the repository using git without '--recursive'
2025-01-20 14:44:06,662: To fix this, please run (from inside your web2py folder):
2025-01-20 14:44:06,663: 
2025-01-20 14:44:06,663:      git submodule update --init --recursive
2025-01-20 14:44:06,663: 
2025-01-20 14:44:06,664: You can also download a complete copy from http://www.web2py.com.
2025-01-20 14:44:06,666:   File "/var/www/ghdev_pythonanywhere_com_wsgi.py", line 31, in <module>
2025-01-20 14:44:06,667:     from gluon.dal import DAL
2025-01-20 14:44:06,670: 
2025-01-20 14:44:06,671:   File "/home/ghdev/web2py/gluon/__init__.py", line 35, in <module>
2025-01-20 14:44:06,671:     import_packages()
2025-01-20 14:44:06,671: 
2025-01-20 14:44:06,671:   File "/home/ghdev/web2py/gluon/__init__.py", line 33, in import_packages
2025-01-20 14:44:06,671:     raise RuntimeError(MESSAGE % package)
2025-01-20 14:44:06,672: ***************************************************
2025-01-20 14:44:06,672: If you're seeing an import error and don't know why,
2025-01-20 14:44:06,672: we have a dedicated help page to help you debug: 
2025-01-20 14:44:06,672: https://help.pythonanywhere.com/pages/DebuggingImportError/
2025-01-20 14:44:06,673: ***************************************************
2025-01-20 14:44:07,512: Error running WSGI application
2025-01-20 14:44:07,541: RuntimeError: web2py depends on pydal, which apparently you have not installed.
2025-01-20 14:44:07,541: Probably you cloned the repository using git without '--recursive'
2025-01-20 14:44:07,541: To fix this, please run (from inside your web2py folder):
2025-01-20 14:44:07,542: 
2025-01-20 14:44:07,542:      git submodule update --init --recursive
2025-01-20 14:44:07,543: 
2025-01-20 14:44:07,543: You can also download a complete copy from http://www.web2py.com.
2025-01-20 14:44:07,543:   File "/var/www/ghdev_pythonanywhere_com_wsgi.py", line 31, in <module>
2025-01-20 14:44:07,543:     from gluon.dal import DAL
2025-01-20 14:44:07,543: 
2025-01-20 14:44:07,544:   File "/home/ghdev/web2py/gluon/__init__.py", line 35, in <module>
2025-01-20 14:44:07,544:     import_packages()
2025-01-20 14:44:07,544: 
2025-01-20 14:44:07,544:   File "/home/ghdev/web2py/gluon/__init__.py", line 33, in import_packages
2025-01-20 14:44:07,544:     raise RuntimeError(MESSAGE % package)
2025-01-20 14:44:07,544: ***************************************************
2025-01-20 14:44:07,545: If you're seeing an import error and don't know why,
2025-01-20 14:44:07,545: we have a dedicated help page to help you debug: 
2025-01-20 14:44:07,545: https://help.pythonanywhere.com/pages/DebuggingImportError/
2025-01-20 14:44:07,545: ***************************************************

[formatted by admin]

Also, I installed it here: ~/.virtualenvs/ghdev_virtual_env_2025/bin

deleted post

Now it's apparently complaining about pydal being missing...

Yes. Suggestions?

I've done a PIP install of pydal in my virtual environment, but that didn't help. I've also added a path to dal.py in the wsgi file and that didn't help.

I sort of solved this issue by deleting the routes.py file in the web2py folder. However, web2py is not finding my apps. Off to another round of debugging!

Mark this item as closed.

Thanks for letting us know