Sigh. I think you’re still missing my point. One further try.
I don’t have (or want) a pyproject.toml
for this use case. That’s *exactly my point. I’m not even in a Python project, or writing one. If it helps, assume I’m writing my script in /tmp
.
… and I don’t want to manage a virtual environment associated with my script. I want the system to do that for me.
Which is great, but they still need me to manage the environment in the sense that I have to pick a name for it, delete it when I’m done, and remember that that environment is associated with my (probably throwaway, but I’m keeping it “just in case”) script.
My ideal here is for scripts which depend on 3rd party libraries to be just as easy to write and use as scripts that only rely on the stdlib. And crucially, for all situations that pure-stdlib scripts can be used in.
The nearest I’ve found is pip-run
, which lets you say __requires__ = ['requests']
in your script, and it will then install requests in a temporary environment when you run your script. Its main disadvantages are that it re-creates the environment every run (slow if you have complex dependencies) and that it has a somewhat clumsy command line syntax. But integrate that functionality with something like hatch run
and you have pretty close to what I’m talking about.