Installing and use weewx with a virtual environment

364 views
Skip to first unread message

gearoid

unread,
Oct 31, 2022, 12:12:24 PM10/31/22
to weewx-user
I'd like to be able to install weewx and run it using a virtual environment instead of using the system's interpreter.

When I run "sudo <path to vevn's python> setup.py install" I get an error about not being able to use both prefix and exec_prefix.
I commented out exec_prefix= in setup.py.
The install runs but a bunch of files are placed in the virtual environment's directory and not in /home/weewx.

I moved those files into /home/weewx myself and it seem to be working.

I'd like to be able to do that without those hacks.  If someone can give some pointers and it's a reasonable thing to be able to do I'd be happy to make the PR.

I'm using Ubuntu, pyenv to install python 3.10.8.
Using python venv to create the 3.10.8 virtual environment and then pip to install the required modules (so no apt installed packages).

Gearoid.

Tom Keffer

unread,
Oct 31, 2022, 1:26:16 PM10/31/22
to weewx...@googlegroups.com
Unfortunately, as you discovered, this is a little tricky. If you run setup.py from the virtual environment, things end up in funny places.

Instead, use the system's python to set things up using setup.py, then switch to the virtual environment to install dependencies, then run weewxd. But, first you'll need configobj, because setup.py requires it. However, DO NOT INSTALL configobj from the weewx distribution subdirectory, because pip will see the setup.cfg and put configobj in a funny spot.

Here's  the way I do it:

# First install configobj. Can be done anywhere, but NOT in the weewx distribution subdirectory
cd /home/weewx
python3 -m pip install --user configobj
# Unpack the tarball, then cd into the resultant subdirectory
tar xvf weewx-4.9.1.tar.gz
cd weewx-4.9.1
# Set up /home/weewx using the system's version of python
python3 setup.py install
# Now set up the venv in /home/weewx
cd /home/weewx
python3 -m venv weewx_venv
# Activate it
source ./weewx_venv/bin/activate
# Install dependencies in the  virtual environment
python3 -m pip install configobj Cheetah3 Pillow pyserial pyusb pyephem
# Now you can run weewxd in the virtual environment
python3 ./bin/weewxd

For running as a systemd daemon, set up your systemd file so that it uses the version of Python in the venv. That is, ExecStart will look something like this:

ExecStart=/home/weewx/weewx_venv/bin/python3 /home/weewx/bin/weewxd /home/weewx/weewx.conf

A major goal of WeeWX Version 5 is to make this all easier. In particular, use pipenv, or similar tool, to install things from pypi.org into a virtual environment. Unfortunately, we may end up with a bit of a hybrid mix because the Python install tools are not really designed to handle data such as the skins and configuration file.

Let me know how things go.

-tk


--
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/8fa1b5ce-7c78-449f-bf56-b9a2b53de99dn%40googlegroups.com.

Tom Keffer

unread,
Oct 31, 2022, 1:37:02 PM10/31/22
to weewx...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages