Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5219

Python • Re: Python program service

$
0
0
It is the latest version of RPiOS, no venv and pip install bme280.

That's not actually very helpful. There are at least four "latest version"s: 32bit lite, 32bit desktop, 64bit lite, and 64bit desktop

And if "latest version" includes RPiOS Legacy that's another four.

Post the output from the following:

Code:

cat /etc/os-release
And tell us about any changes you've made from the default installation too.

And post your .service file.

[edit]
Oh, and "latest version" installed a month ago is not the same as the "latest version" installed today. Though that may not matter for python.
[/edit]
PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"
NAME="Raspbian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"


Service file written following a tutorial.

[Unit]
Description=Gets temperature data and sends to database
After=multi-user.target

[Service]
Type=simple
ExecStart=/usr/bin/python /home/es2800/Desktop/Code/weatherStation/WS_main.py
Restart=on-abort

[Install]
WantedBy=multi-user.target

So not the latest then.

Looks to me like you installed the bme280 module only for the user es2800 but your service is running as root (that's the default asyou've not specified otherwise).

Option 1: As already suggested sudo pip install bme280. Will work but deprecated going forward. Will not work on Bookworm.

Option 2: Try installing from apt sudo apt update && sudo apt install -y python3-bme280 but that may get you a different version than pip installs.

Option 3: Run your service as es2800. You can do so as follows:
  1. Code:

    sudo systemctl stop <service name>
  2. Add the following two lines to the [Service] section of your .service file

    Code:

    User=es2800Group=es2800
  3. Code:

    sudo systemctl daemon-reload
  4. Code:

    sudo systemctl start <service name>
Option 3 is preferred where you code does not need root privileges.

Option 2 is the preferred method to install a python module in a system wide manner on Bookworm.

Statistics: Posted by thagrol — Wed Nov 27, 2024 1:51 pm



Viewing all articles
Browse latest Browse all 5219

Trending Articles