As Carter writes in his Python Virtual Environment Usage on Raspberry Pi guide:
Starting with the October 10, 2023 Bookworm release of the Raspberry Pi OS, the use of Python Virtual Environments (venv) when pip installing packages is required. No more sudo pip. This will break things and require learning new things. Yeah.
You will need to setup a Python virtual environment (venv) on your Raspberry Pi 5 for this project. Don't worry though! If you follow along with the guide step by step, you'll be just fine.
Always venv
On the Other Ideas page in the venv guide, there is a tip for having the virtual environment enabled automatically at boot by editing the .bashrc
file (sudo nano .bashrc
) and adding this line to the bottom:
source home/user/venv/bin/activate
Where venv
is the name of your virtual environment. You can take this a step further by adding the alias for running Python scripts as sudo
to your .bashrc
file as well:
alias gogo='sudo -E env PATH=$PATH python'
You can change gogo
to any command you want. This way, every time you boot up your Pi, you'll have your Python venv enabled and you'll be able to use your alias for running Python scripts.
Text editor powered by tinymce.