Hi all,
Completely wet behind the ears here. I’m trying to get my head around using the pi with the Automation hat.
Why is the automation hat libraries installed in a “virtual environment”?
Sure, I can use the examples no worries, but how do I use the hat in a normal python script without having to call up the virtual environment every time?
Sorry if this is dumb but if I write a script and call
import automationhat
Without being in the “virtual environment”
It fails
Is the installation script on the Pimoroni site just for the examples? The script won’t work if you tell it no to the virtual environment
And Adafruit’s guide is a bit chunkier but contains lots of good info (including how you can set up a Python script as a service so it will run at boot):
The basic rationale is that you run into trouble if you want to manage your Python packages with two different package-managers that have a different idea of what is the “current” or “correct” package version. All Linux-systems have their own package manager (e.g. Debian/PiOS has “apt”). And Python has also a package-manager called “pip”.
Some packages are available from both, some only from a single package manager. Virtual environments are a safe space for pip to operate on - i.e. pip won’t interfere with apt. And you can have multiple venvs, in case you have programs that need a package in version A and the other in version B.
Very often you don’t encounter problems though if you mix package managers. That is why many people think venvs are not necessary. But sooner or later, you will run into problems. For single application systems, like running on a Pi-Zero, this is unlikely, but if you use your Pi for daily work, it is only a matter of time.