:: Re: [DNG] Python and Virtual Enviro…
Página Principal
Delete this message
Reply to this message
Autor: Lars Noodén
Data:  
Para: dng
Assunto: Re: [DNG] Python and Virtual Environments
On 2/11/25 20:19, Vince Mulhollon wrote:
> On Tue, Feb 11, 2025 at 10:01 AM Olaf Meeuwissen <olaf@???> wrote:
>> I don't know why you want to avoid virtual environments
>
> I'm not OP but I have experience trying to run python scripts from
> crontab in various virtual environments and its ROUGH.
>
> /bin/sh may or may not support the source command. You can run a
> /bin/sh script to call a /bin/bash script to call the venv Python
> script. Or set the SHELL env var in crontab if your local crontab
> supports that (to run /bin/bash for all crontabs instead of /bin/sh)

[snip]

You can point to the venv's Python interpreter in the Python script's
shebang. For example if you have a venv in /usr/local/venv/ then

    #!/usr/local/venv/bin/python3


That'll launch the script within the venv

/Lars