zewelor / bt-mqtt-gateway

A simple Python script which provides a Bluetooth to MQTT gateway, easily extensible via custom workers. See https://github.com/zewelor/bt-mqtt-gateway/wiki for more information.
MIT License
549 stars 116 forks source link

README venv installation instructions are incorrect #274

Open harristom opened 9 months ago

harristom commented 9 months ago

On a clean system, following the README instructions for venv installation exactly as written doesn't work.

$ source .venv/bin/activate
$ sudo ./gateway.py
Traceback (most recent call last):
  File "/home/pi/bt-mqtt-gateway/./gateway.py", line 11, in <module>
    import logger
  File "/home/pi/bt-mqtt-gateway/logger.py", line 3, in <module>
    import yaml
ModuleNotFoundError: No module named 'yaml'

I admit I'm not super familiar with python but afaik it doesn't make sense to activate the venv and then run sudo, as the env vars (specifically the python path) set by activating will anyway be ignored once we are running as a root so we will effectively be running outside the venv and thus will be missing the dependencies that were installed inside it.

./gateway.py would run using the venv packages but on my system at least it fails because you need to be root to run the BT scan. Calling the venv's python binary directly as root seems to work (no need to activate venv first but equally wouldn't do any harm): $ sudo .venv/bin/python gateway.py

Similarly, service.sh needs to be edited. It correctly sets the PATH to include the venv path but then undoes that work by using sudo, which is unnecessary as systemd services already run as root afaik. Simply removing sudo from the last line fixes it, i.e.: python3 ./gateway.py "$@"