is there a guide / discussion / hints for migrating apps to python3?

130 views
Skip to first unread message

pa...@cancamusa.net

unread,
Sep 5, 2020, 6:08:35 AM9/5/20
to web2py-users

Hello:

I know I'm late, but I'm migrating my app to python3. The 2to3 library did most of the work. Most of the remaining errors were simple to solve, having to do with string, bytes, encode and decode.

I found it odd that web2py returns str objects to the db queries, but the xml() method returns a bytes object. This made a few replacements and regex break, but it wasn't hard to fix. The translation object T() works either way, which is great.

Two issues I would like to comment:
  • the gluon.contrib.json module breaks. It can be fixed by 2to3 and a bit of manual tinkering. I guess it is not necessary any more and the job can be done with the standard library json, is it?
  • Can you point me to documentation / google group thread / whatever concerning a standard as-in-the-book install with uwsgi, emperor, nginx, etc. I can't find the right place to tell uwsgi to use python3. I would actually like to switch from python2 to python3 first in a test site, then in production, so for a time, there would be one web2py installation in python2 and other installation, with all its apps, in python3. Is this even possible? I will be researching this guide in the meantime: https://uwsgi-docs.readthedocs.io/en/latest/WSGIquickstart.html#bonus-multiple-python-versions-for-the-same-uwsgi-binary
Regards

pa...@cancamusa.net

unread,
Sep 5, 2020, 11:29:17 AM9/5/20
to web2py-users
If I got it right, it is just fine to run two web2py installs, one with python2, the other with python3, it is only required to edit wsgihandler.py and let it start with

#!/usr/bin/env python3

instead of

#!/usr/bin/env python

Regards

tuan.ngo

unread,
Sep 9, 2020, 10:57:50 AM9/9/20
to web...@googlegroups.com

I found some link concern with install py3 with Nginx & uwsgi.

https://stackoverflow.com/questions/60115077/is-there-a-proper-way-to-make-web2py-use-python3-instead-of-python2

https://gist.github.com/simoncoulton/2625954

Anyway, I use Apache with libapache2-mod-wsgi-py3. It’s just work fine.

 

Sent from Mail for Windows 10

--
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/44c90a39-754a-4411-8954-0c5eb9a7e555n%40googlegroups.com.

 

Jim S

unread,
Sep 9, 2020, 6:27:55 PM9/9/20
to web2py-users

To unsubscribe from this group and stop receiving emails from it, send an email to web...@googlegroups.com.

pa...@cancamusa.net

unread,
Sep 9, 2020, 10:34:29 PM9/9/20
to web2py-users
Thank you very much, that is absolutely relevant.

I did not install uwsgi through apt, but used pip which is the recommended way in the ubuntu install script, so I'll have to find out how to install the python3 plugin. Probably I will just pip uninstall uwsgi, then apt install it and follow the exact instructions you posted.

Regards, have a nice day!

pa...@cancamusa.net

unread,
Sep 9, 2020, 10:40:16 PM9/9/20
to web2py-users
Thanks, Jim, though that link was not helpful. It is not clear to me that installing uwsgi through pip3 will result in uwsgi using the python3 plugin, but anyway that is definitely not what I need right now, which is to test a python3 app while I keep a python2 one.

Anyway, I'm well served by tua...'s links, I'll just have to find some high-attention-low-traffic timespan to attempt the solution ;-)

pa...@cancamusa.net

unread,
Sep 26, 2020, 2:53:13 AM9/26/20
to web2py-users
For the record, apt installing uwsgi-plugin-python3 did not work for me. I considered compiling uwsgi manually with both plugins, and eventually migrated the whole server at once, since I have been using python3 without problems for some weeks. It was just a matter of pip uninstall uwsgi, pip3 install uwsgi, restart the uwsgi unit and dealing a posteriori with the compiled pyc files, which would have been easier to do in advance :-[. Summary:
  1. backup all the error tickets, which you will lose because of the pickle python2 and python3 incompatible formats (I guess you can carry them to a separate offline python2 server, or maybe improve the admin app code to try both pickle formats)
  2. remove all the complied apps
  3. update your /etc/uwsgi/sites/*.ini files and your crontab to run python3 instead of python2
  4. pip uninstall uwsgi
  5. pip3 install uwsgi
  6. restart the uwsgi unit
  7. compile your app again
I think that's all, of course once you have tested-to-exhaustion your app with python3 locally.

Have a nice weekend
Reply all
Reply to author
Forward
0 new messages