vgenovpy
vgenovpy

Reputation: 146

Python3 venv is not activating correctly with supervisor

I'm using supervisor 4.1.0 to run a Python script. The Python script needs a venv activated to run properly and it does without using supervisor.

When running the python script from supervisor, I'm getting one dependency missing, but all the other dependencies are working just fine, the supervisor file contains the following conf:

[program:counter]
directory=/home/dell/vito/counter
command=bash /home/dell/vito/counter/venv/bin/python3 /home/dell/vito/counter/main.py
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
stderr_logfile=/var/log/counter/counter.err.log
stdout_logfile=/var/log/counter/counter.out.log
user=dell

And even thoug the process is running, the application is not working and I'm getting the following error on the counter.err.log file:

TERM environment variable not set.
/bin/sh: 1: pip: not found

and in the out, which explain the problem:

Ultralytics YOLOv8.2.22 🚀 Python-3.8.10 torch-2.0.0+nv23.05 CUDA:0 (Orin, 7337MiB)
Loading /home/avacon/vito/counter/models/best320n_29052024.engine for TensorRT inference...
requirements: Ultralytics requirement ['nvidia-tensorrt'] not found, attempting AutoUpdate...

If in the command variable I put python3 main.py, I get the typical error of ultralytics module not found error etc...

So the venv is being activated, but partially?

I've tried setting environment variable on the conf file:

environment=HOME=/home/dell/vito/counter/venv/bin and other variations like =PATH or .../venv /venv/bin/activate and so on.

I also tried to solve the problem using google and following this How to use virtualenvwrapper in Supervisor? but it didn't solve my issue

What I'm expecting is to run the script with the correct env

Upvotes: 2

Views: 85

Answers (1)

Marc Condon
Marc Condon

Reputation: 430

The environment isn't primed right using activate. replace

command=bash /home/dell/vito/counter/venv/bin/python3 /home/dell/vito/counter/main.py

with

command=bash /home/dell/vito/counter/venv/bin/activate && /home/dell/vito/counter/venv/bin/python3 /home/dell/vito/counter/main.py

Upvotes: 0

Related Questions