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

Python • Re: activate venv from script?

$
0
0
I have a setup with a headless pi and the gravitrax bluetooth bridge.
I'd like to have a script running on boot, this script will wait for a button push.
When I push the button the program needs to connect to the gravitrax bridge, this uses a library I installed in a venv.
So my question is, how to activate the venv ?

There are many ways. Some examples all assume the venv is in $HOME/venv:
  1. Code:

    source $HOME/venv/bin/activate && python my-program.py
  2. Use a shell swcript:

    Code:

    #!/bin/bashsource $HOME/venv/bin/activatepython my-program.py
  3. Use the python interpreter in the venv directly:

    Code:

    $HOME/venv/bin/python my-program.py
Or is it better practise to have the venv active all the time?

No. That defeats the point of a venv
is this possible on boot?

Running A Program At Start Up A Beginner's Guide

Statistics: Posted by thagrol — Fri Feb 06, 2026 12:50 pm



Viewing all articles
Browse latest Browse all 1579

Trending Articles