recommended shebang for python scripts based on sage.all lib

28 views
Skip to first unread message

Laurent Faureytier

unread,
Sep 28, 2024, 4:36:17 AM9/28/24
to sage-support
Hi,

I maintain a bunch of standalone python scripts, some of which rely on sage python lib. I find very convenient to make it possible for users to invoke the scripts from the command line by simply typing e.g. from an Ubuntu 22.04 LTS bash prompt:
$ ./myscript.py

To do that, the scripts start with the following shebang and some sage lib import directive like in the following example:
#!/usr/bin/env python3
from sage.all import GF,EllipticCurve,gcd,log

Users who installed sage python libs in a specific virtualenv can just 'activate' such virtual env before invoking the script and it just works all the same. I'm assuming that is not bad practice but if you think it is, I'm open to suggestions.

Now here comes the question. I have just upgraded my distrib to Ubuntu 24.04 LTS which does not support sage. I had to build sage from source, which is OK. Then, to run my python scripts, it seems I only have two simple options:

1. start a sage sub-shell which brings a full custom environment:

[myprompt]$ ${my_local_sage_build_dir}/sage -sh
[sage_custom_prompt]$ ./myscript.py

2. invoke python interpreter from sage local build dir to run my script:

myprompt$ ${my_local_sage_build_dir}/sage -python ./myscript.py

Instead of above solutions, is there a way to "just" activate the python virtual env that comes with sage local build ? (for instance, there is no 'activate' script in ${my_local_sage_build_dir}/venv/bin )

Thanks in advance.

Reply all
Reply to author
Forward
0 new messages