2

I have been using web2py with Python v2 for a couple of years, and now I would like to switch to Python 3 runtime, but I am not sure what is the proper way?

I am usually installing web2py using the installation script available from here, and it is running under Ubuntu 18.04.

djordje@vmi:~$ python --version
Python 2.7.17
djordje@vmi:~$ python3 --version
Python 3.6.9
djordje@vmi:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.4 LTS
Release:        18.04
Codename:       bionic

I tried to set the default Python version to 3, as explained on this link using:

update-alternatives --remove python /usr/bin/python2
update-alternatives --install /usr/bin/python python /usr/bin/python3 10

and it sets the default Python to v3, but even after rebooting the server - web2py still runs with Python v2.

Version
2.18.5-stable+timestamp.2019.04.08.04.22.03
(Running on nginx/1.14.0, Python 2.7.17)

Is there a recommended way to set web2py to run with Python 3 on Linux?

Dan D.
  • 73,243
  • 15
  • 104
  • 123
Djordje
  • 124
  • 7
  • Have you been able to find a working solution? – user2436428 Jan 16 '21 at 06:36
  • So far, I haven't found a better solution than the one below. Also tried Tim Nyborg's recommendation, but it did not work every time. – Djordje Jan 18 '21 at 09:45
  • Yes, it finally worked. Actually there were two installations of uwsgi on my server, in /usr/bin/ and /usr/local/bin. Since it was configured to use /usr/local/bin/uwsgi and I was not aware of this fact, it didn't work initially – user2436428 Jan 19 '21 at 10:48

2 Answers2

3

After days of searching, it seems that I found something rather easy to implement, and is working in my case. Thanks to the following link.

I installed the following:

apt install uwsgi-plugin-python3

and then I listed the installed plugins under the /usr/bin:

ls /usr/bin/uwsgi_python*

There were two: uwsgi_python3 and uwsgi_python36 so I used:

update-alternatives --set uwsgi /usr/bin/uwsgi_python36

And after rebooting the server, it worked:

2.18.5-stable+timestamp.2019.04.08.04.22.03
(Running on nginx/1.14.0, Python 3.6.9)

Maybe there is a better (preferred way), but I did not want to add a virtual environment, nor change the default OS Python version. This way, I just updated uwsgi runtime.

Djordje
  • 124
  • 7
1

We were able to switch between python 2 and 3 on our web2py servers by uninstalling one version's uwsgi pip package, installing the other, and restarting the service:

pip uninstall uwsgi
pip3 install uwsgi
service uwsgi restart
Tim Nyborg
  • 1,599
  • 1
  • 9
  • 16