shell.py, unqualified exec is not allowed

61 views
Skip to first unread message

apinho

unread,
Feb 5, 2024, 11:37:34 AMFeb 5
to web2py-users
Hello everyone,

I just migrated an old (2017-ish) web2py app, which was still hosted on a user machine, running on Rocket HTTP server.

The app is now on a CentOS 7 VM, under nginx/uwsgi using HTTPS.
Web2py version is 2.27.1, over Python 2.7.5, in a virtualenv.

All is OK as for the app itself, but now I as trying to setup cron to to delete old sessions, and I'm stuck with this :
$ python web2py.py -S <myapp> -M -R scripts/sessions2trash.py -A -o -X 3600 -f -v
Traceback (most recent call last):
  File "web2py.py", line 44, in <module>
    import gluon.widget
  File "/home/apinho/web2py/web2py/gluon/widget.py", line 28, in <module>
    from gluon.console import console, is_appdir
  File "/home/apinho/web2py/web2py/gluon/console.py", line 53, in <module>
    from gluon.shell import die
  File "/home/apinho/web2py/web2py/gluon/shell.py", line 305
    exec(read_pyc(pycfile), _env)
SyntaxError: unqualified exec is not allowed in function 'run' it contains a nested function with free variables

I really have no clue what to do. There is little help online. The only one I could find says that upgrading to Python 2.7.18 would do the trick, but that would most probably wreck Centos7 (Which I am stuck with, for it is my company's mandatory Linux distro for production environments).

Any help would be much appreciated.
Alexandre

Massimiliano

unread,
Feb 6, 2024, 12:25:31 PMFeb 6
to web...@googlegroups.com
Take a look to pyenv or nix to install a python version apart from the system

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/575fdca2-1b6d-4107-8b99-9c5eeeee5a30n%40googlegroups.com.


--
Massimiliano

apinho

unread,
Feb 6, 2024, 2:40:00 PMFeb 6
to web2py-users
Hi,

Thank you.

I was under the impression that web2py was only compatible with Python2.7, and that py4web was for Python3x.
I now understand that py2web has been modified and is also compatible with Python3, up to 3.11.

That definitely opens new horizons for me. I might try to install Python3 alongside, and use it's venv.
I think that might be less confusing than trying to install a newer Python2.7 version, on this system, do you agree ?

Is migrating an web2py from Python2.7 to Python 3x a straightforward task ? Or might it need some code refactoring ?

Alexandre

Dave S

unread,
Feb 29, 2024, 4:21:40 AMFeb 29
to web2py-users
On Tuesday, February 6, 2024 at 11:40:00 AM UTC-8 apinho wrote:
Hi,

Thank you.

I was under the impression that web2py was only compatible with Python2.7, and that py4web was for Python3x.
I now understand that py2web has been modified and is also compatible with Python3, up to 3.11.

That definitely opens new horizons for me. I might try to install Python3 alongside, and use it's venv.
I think that might be less confusing than trying to install a newer Python2.7 version, on this system, do you agree ?

Is migrating an web2py from Python2.7 to Python 3x a straightforward task ? Or might it need some code refactoring ?

Alexandre

I would say that >90% is straightforward.   Clean up all your "print" statements to "print()" calls, and that will get most of it.  There are a couple of other syntactical changes, but not very many.  Depending on your needs, though, there may be some standard library that is no longer standard library.  I encountered this around some special cases for needing to use urllib2.

Good luck!

/dps
Reply all
Reply to author
Forward
0 new messages