
Single File, Editable Python Scripts with Dependencies - alanfranzoni
https://www.franzoni.eu/single-file-editable-python-scripts-with-dependencies/
======
pmontra
It's virtually equivalent to virtualenv. Virtualenv creation, installation and
activation can be scripted. Why shouldn't we use the real thing?

~~~
alanfranzoni
Feel free to use what you feel is good for you. But this makes a lot of sense
(to me!) for simpler scripts. Imagine cron jobs or other "internal" scripts,
maybe things that you launch on a cluster via ansible or other tools for
periodic or one shot tasks... things like that.

Virtualenv is "stateful" \- you need a) to have it installed on the target
system b) to deliver both your script AND the requirements.txt file c) to
launch virtualenv d) execute your script via virtualenv.

Far more complex than just "run this script and you're done", right? If an
"embedded virtualenv" functionality existed, something like

    
    
        import virtualenv
        virtualenv.install_requirements("asd==1.2.3")
        # from there, the software goes on with the requirements actually available
    

Then my snippet would make no sense.

Of course (but I don't know whether this was the real suggestion) I could
evaluate using virtualenv (if available) instead of manually setting the
sys.path. But I found that to be a bit more complex (virtualenv could actually
be installed with a different Python interpreter since it allows the -p
parameter, while pip is generally bound to each specific interpreter).

