WeeWX v5 pip Install into venv

164 views
Skip to first unread message

gary....@gmail.com

unread,
Aug 25, 2023, 12:27:47 AM8/25/23
to weewx-user
I installed v5 from an alpha long ago. I've upgraded along the way with little issue.

This was on my test machine, a drive went sideways and a complete rebuild was in order. One good thing, a shiny new SSD is in place.

Now, it seems that a venv is preferred.

So, how to accomplish that? I have zero experience with a venv. I have had to use the package manager to get a couple of python packages though and don't know how that will work with a venv.

How will this work for systemctl (service)?
I install and manage WeeWX as root on v4.x.x but I'm going to attempt to run as a user with venv. Where will the WeeWX directories reside?

If there is an up to date doc/wiki dealing with this, kindly point me towards it.

vince

unread,
Aug 25, 2023, 12:41:06 AM8/25/23
to weewx-user
draft docs are https://www.weewx.com/docs/5.0/

For the venv you do a 'source weewx-venv/bin/activate' then do a pip install to add modules within the venv.   All you have to remember is to activate the venv before running weectl, as well as read the docs for the new syntax for doing things.  It's pretty easy to pick up.

systemctl works fine.  Just go with it :-)

Graham Eddy

unread,
Aug 25, 2023, 5:24:11 AM8/25/23
to WeeWX User
use ‘python3 -m venv ~/venv’ to create the environment in ~/venv.
then in your shell run ’source ~/venv/bin/activate’ to set up the shell environment (initialised python bindary, PYTHONPATH etc). i put this in my ~/.bashrc

a key trick is that running the initialised python binary (~/venv/bin/python3) on its own sucks in the environment - really, really handy in systemctl unit files
⊣GE⊢

Greg Troxel

unread,
Aug 25, 2023, 10:27:10 AM8/25/23
to Graham Eddy, WeeWX User
Graham Eddy <g...@geddy.au> writes:

> use ‘python3 -m venv ~/venv’ to create the environment in ~/venv.
> then in your shell run ’source ~/venv/bin/activate’ to set up the shell environment (initialised python bindary, PYTHONPATH etc). i put this in my ~/.bashrc
>
> a key trick is that running the initialised python binary (~/venv/bin/python3) on its own sucks in the environment - really, really handy in systemctl unit files
> ⊣GE⊢

I have never activated a venv and always been puzzled by this being the
standard approach. Simply running the venv' python binary, either
explicitly on the command line, or via a #!, has been entirely fine. I
have home assistant working this way, which is super comlicated compared
to weewx.

I also run, when in the venv dir

bin/pip install foo

which runs the venv's pip which uses the venv's python.

I'm glad to hear that there is no special 'have to activate' rule about
weewx.



Tom Keffer

unread,
Aug 25, 2023, 11:12:48 PM8/25/23
to weewx...@googlegroups.com, Graham Eddy
Running the venv's binaries (versus activation) is completely acceptable. Indeed, that's what the systemctl unit file does.

--
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/rmi1qfre7t2.fsf%40s1.lexort.com.

Greg from Oz

unread,
Aug 25, 2023, 11:23:16 PM8/25/23
to weewx-user
I am running V5 and I put all my venv files into /opt so I have to remember to run the full path:
EG sudo /opt/weewx/weewx-venv/bin/wee_reports --config=/opt/weewx/weewx-data/weewx.conf

To use the venv I run :source /opt/weewx/weewx-venv/bin/activate
also if you want to exit the venv type the command: deactivate

Like Tom said the systemctl uses the full path:
ExecStart=/opt/weewx/weewx-venv/bin/python3 /opt/weewx/weewx-venv/lib/python3.11/site-packages/weewxd.py /opt/weewx/weewx-data/weewx.conf

I am running weewx as root user but my config files have my user permissions and ownership.

gary....@gmail.com

unread,
Aug 26, 2023, 3:33:55 PM8/26/23
to weewx-user
Thanks guys, installed into a new ubuntu 23.04 instance using venv and as a normal user.
I like the new install from a url for extensions.
Reply all
Reply to author
Forward
0 new messages