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

Python • Multiple python scripts in virtual environment

$
0
0
I have been using python scripts successfully for a few years but recently upgraded to Pi5 running bookworm. The virtual environment that python uses now proved to be a hurdle but I think that I got it figured out after several days of experimenting and searching. the web. Given that, I have a couple of questions to which I haven't found the answer. My pi5 runs some python scripts to collect various bits of data and perform tasks throughout the day and night i.e. backup, collect room temperatures, perform speed tests for internet connection health, etc. All of the scripts are started via cron and then stopped until the next call from cron.

Should each script run in it's own virtual environment or should I have only only ONE virtual environment in which all of the scripts run?

I have figured out how to start scripts using this in a bash shell script:

Code:

source /path/to/venv/activate && /path/to/script.py
Should the virtual environment be deactivated at the completion of each script? And is so, how would I deactivate the environment at the end of the script?

Statistics: Posted by Reillysdad — Sun Dec 08, 2024 1:12 pm



Viewing all articles
Browse latest Browse all 4834

Trending Articles