Autor: Olaf Meeuwissen Data: Para: Vince Mulhollon CC: dng Assunto: Re: [DNG] Python and Virtual Environments
Hi,
Vince Mulhollon <vince@???> writes:
> 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.
I've run into a number of surprises with specifying cron jobs myself and
none of those were related to running python scripts in various virtual
environments. All my issues originated from not understanding what cron
provides as a run time environment. I have had similar experiences with
sudo.
Before blaming the python and/or its virtual environments, make sure you
understand the context you stuff will be running in. For one thing, do
not expect any of your interactive login shell to be taken into account.
> /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)
Both cron and anacron will let you set SHELL but why not use a #! in
whatever script you want to run to be specific about what interpreter
you want the rest of the file to be processed with. By the way, with
the usr-merge mandatory now maintainers seem to be shifting to
#!/usr/bin/sh
If necessary, you can even say
#!/usr/bin/env python
so it'll observe the PATH setting that's in effect. That may or may not
be what you or the system set in your shell customizations.
> pipenv won't run with a locale set and may or may not have weird PATH
> issues. Or maybe it works now.
I haven't tried but maybe you have a smoother ride with pipx.
> Why we have to deal with /bin/sh instead of just use bash everywhere
> in 2025 is another good question, if I never see /bin/sh again I'll be
> OK.
Just wait until /usr/bin/zsh becomes the norm ;-P
> [...] --
Olaf Meeuwissen