How to change weewx service from python2 to python3 on Debian

461 views
Skip to first unread message

Gordon Dickens

unread,
Jan 26, 2021, 4:58:49 PM1/26/21
to weewx-user
How do I make weewx use python3 instead of python2?  I initially installed weewx on Debian using the Debian package over a year ago and it was originally setup to use python2. I recently upgraded to weewx 4.3.0 with the Belchertown skin version 1.2 and so I want to also upgrade to python3.   The normal way to change default packages in Debian is with the update-alternatives command, however, when I set python3 as the default, weewx continues to use python2 as seen from the command, "ps aux | grep weewx" whose output contains:

python2 /usr/share/weewx/weewxd --daemon --pidfile=/var/run/weewx.pid /etc/weewx/weewx.conf

So, the service is started with python2.  How do I change the weewx service to use python3?

Thanks,

Gordon

Tom Keffer

unread,
Jan 26, 2021, 5:04:29 PM1/26/21
to weewx-user
Easiest is to just follow the install directions in the Debian guide:

wget -qO - https://weewx.com/apt/weewx-python3.list | sudo tee /etc/apt/sources.list.d/weewx.list
sudo apt-get update
sudo apt-get install weewx


--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/807bfd14-5724-4116-b369-c7d2d49f15b9n%40googlegroups.com.

Colin Larsen

unread,
Jan 26, 2021, 5:12:36 PM1/26/21
to weewx-user
I remember I had to change /etc/default/weewx it to tell Weewx to start with Python3

WEEWX_PYTHON=python2    <== change to python3

WEEWX_BINDIR=/usr/share/weewx

WEEWX_BIN=/usr/bin/weewxd

WEEWX_CFG=/etc/weewx/weewx.conf


Colin

Tom Keffer

unread,
Jan 26, 2021, 5:17:17 PM1/26/21
to weewx-user
Yes, that will work, but it also assumes that all the prerequisites have been installed. The Python 3 prereqs are different from Python 2.

Gordon Dickens

unread,
Jan 27, 2021, 2:44:40 PM1/27/21
to weewx-user
Thanks to Tom, Rainer and Colin for your prompt replies!

I followed the instructions verbatim in the Debian guide as Tom suggested.  Afterwards, I get the following dialog with the command "systemctl status weewx":
weewx_status_errors.png

I also tried to reinstall with the command "apt --reinstall install weewx"  but the results were the same.

Tom, where did I go wrong and what do you recommend?

I made a complete system backup before I attempted the migration. So, if I need to, I can revert to the Python2 version but I would rather fix it now.

Thanks,

Gordon

vince

unread,
Jan 27, 2021, 2:51:58 PM1/27/21
to weewx-user
Any time you see that error, you are running python2 code that has not been updated to python3.
You need to update your weather34 software to a python3-compliant version.

Gordon Dickens

unread,
Jan 27, 2021, 2:53:30 PM1/27/21
to weewx-user
In my previous post I thought that it would be better to send the errors via an image, however, I am not sure that was the best way.  In any event, here are the errors from the output of "systemctl status weewx":

root@zeebytes:/etc/weewx# systemctl status weewx
● weewx.service - LSB: weewx weather system
   Loaded: loaded (/etc/init.d/weewx; generated)
   Active: active (exited) since Wed 2021-01-27 14:34:43 EST; 10s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 31379 ExecStart=/etc/init.d/weewx start (code=exited, status=0/SUCCESS)

Jan 27 14:34:43 zeebytes.org python3[31396]: weewx[31396] CRITICAL __main__:     ****      self.loadServices(config_dict)
Jan 27 14:34:43 zeebytes.org python3[31396]: weewx[31396] CRITICAL __main__:     ****    File "/usr/share/weewx/weewx/engine.py", lin
Jan 27 14:34:43 zeebytes.org python3[31396]: weewx[31396] CRITICAL __main__:     ****      obj = weeutil.weeutil.get_object(svc)(self
Jan 27 14:34:43 zeebytes.org python3[31396]: weewx[31396] CRITICAL __main__:     ****    File "/usr/share/weewx/weeutil/weeutil.py",
Jan 27 14:34:43 zeebytes.org python3[31396]: weewx[31396] CRITICAL __main__:     ****      mod = __import__(module)
Jan 27 14:34:43 zeebytes.org python3[31396]: weewx[31396] CRITICAL __main__:     ****    File "/usr/share/weewx/user/weather34.py", l
Jan 27 14:34:43 zeebytes.org python3[31396]: weewx[31396] CRITICAL __main__:     ****      except Exception, e:
Jan 27 14:34:43 zeebytes.org python3[31396]: weewx[31396] CRITICAL __main__:     ****                      ^
Jan 27 14:34:43 zeebytes.org python3[31396]: weewx[31396] CRITICAL __main__:     ****  SyntaxError: invalid syntax
Jan 27 14:34:43 zeebytes.org python3[31396]: weewx[31396] CRITICAL __main__:     ****  Exiting.

Please reply with any suggestions.

Thanks,

Gordon Dickens

Gordon Dickens

unread,
Jan 28, 2021, 11:10:05 AM1/28/21
to weewx-user
Thanks Vince for pointing out the problem!  I removed the Weather34 skin and the errors stopped.  However, I am now getting a very similar error but for my mqtt extension.  The command "systemctl status weewx" is now generating the following error dialog:

● weewx.service - LSB: weewx weather system
   Loaded: loaded (/etc/init.d/weewx; generated)
   Active: active (exited) since Thu 2021-01-28 10:56:59 EST; 4s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 29276 ExecStart=/etc/init.d/weewx start (code=exited, status=0/SUCCESS)

Jan 28 10:56:59 zeebytes.org python3[29292]: weewx[29292] CRITICAL __main__:     ****      self.loadServices(config_dict)
Jan 28 10:56:59 zeebytes.org python3[29292]: weewx[29292] CRITICAL __main__:     ****    File "/usr/share/weewx/weewx/engine.py", line 161, in loadServices
Jan 28 10:56:59 zeebytes.org python3[29292]: weewx[29292] CRITICAL __main__:     ****      obj = weeutil.weeutil.get_object(svc)(self, config_dict)
Jan 28 10:56:59 zeebytes.org python3[29292]: weewx[29292] CRITICAL __main__:     ****    File "/usr/share/weewx/weeutil/weeutil.py", line 1093, in get_object
Jan 28 10:56:59 zeebytes.org python3[29292]: weewx[29292] CRITICAL __main__:     ****      mod = __import__(module)
Jan 28 10:56:59 zeebytes.org python3[29292]: weewx[29292] CRITICAL __main__:     ****    File "/usr/share/weewx/user/mqtt.py", line 197
Jan 28 10:56:59 zeebytes.org python3[29292]: weewx[29292] CRITICAL __main__:     ****      except KeyError, e:
Jan 28 10:56:59 zeebytes.org python3[29292]: weewx[29292] CRITICAL __main__:     ****                     ^
Jan 28 10:56:59 zeebytes.org python3[29292]: weewx[29292] CRITICAL __main__:     ****  SyntaxError: invalid syntax
Jan 28 10:56:59 zeebytes.org python3[29292]: weewx[29292] CRITICAL __main__:     ****  Exiting.

So, it appears  that weewx is now using python3 to attempt to execute python2 code for the mqtt extension.   The weewx mqtt documentation states that one of the weewx/mqtt dependencies, python-cjson, is optional, and currently not supported with python3.  So, how do I get weewx/Belchertown's mqtt extension to work with python3 or is that possible?

Thanks again in advance for everybody's advice.

Gordon

vince

unread,
Jan 28, 2021, 12:24:05 PM1/28/21
to weewx-user
On Thursday, January 28, 2021 at 8:10:05 AM UTC-8 gldic...@gmail.com wrote:
Jan 27 14:34:43 zeebytes.org python3[31396]: weewx[31396] CRITICAL __main__:     ****      except Exception, e:
Jan 27 14:34:43 zeebytes.org python3[31396]: weewx[31396] CRITICAL __main__:     ****                      ^
Jan 27 14:34:43 zeebytes.org python3[31396]: weewx[31396] CRITICAL __main__:     ****  SyntaxError: invalid syntax
Jan 27 14:34:43 zeebytes.org python3[31396]: weewx[31396] CRITICAL __main__:     ****  Exiting.

As I said yesterday, when you see that error, you need to 'upgrade' the extension throwing the error to a newer python3-compliant version.  Don't 'remove' the extension or skin.  'Upgrade' it to the current version. Belchertown with MQTT works just fine under python3 if you go to the latest version of the MQTT extension.

The webpage you're looking at is a bit confusingly written.

You want to simply do "sudo pip3 install paho-mqtt" to install the prerequisite python3 library since you are running weewx under python3.   Then upgrade your weewx-mqtt extension with wee_extension as the webpage shows.  Then restart weewx.

It's that simple.
 

Gordon Dickens

unread,
Jan 28, 2021, 12:58:33 PM1/28/21
to weewx-user
Hi Vince,

Your advice worked!  I already had the python3 version of paho-mqtt installed and all that I had to do to get it to work was to reinstall the mqtt extension with "sudo wee_extension --install weewx-mqtt.zip" and everything was fixed.  Previously, I didn't think that I needed to reinstall the mqtt extension since it appeared to be the same code base as was installed with python2, however, reinstalling it fixed it.

FYI,

Gordon
Reply all
Reply to author
Forward
0 new messages