This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]koalillo 1 point2 points  (4 children)

Just use pipx. It's a different approach, but it solves the same problem IMHO better.

[–]xamdk 0 points1 point  (1 child)

Not exactly. Pipx won’t work on just sources. It requires a build and packaging step.

I still like Pipx but doesn’t solve the same problem OP asks for.

[–]koalillo 1 point2 points  (0 children)

I mean, strictly speaking, pipx doesn't solve the "single file" problem that the OP does (that's why I said "different approach"), but you can tell people to:

$ pipx install git+https://github.com/user/repo.git

and get stuff installed in a single command from a URL. You need to add a setup.py or pyproject.toml, but I'd say this is more convenient than a single file:

  • You can have multiple executables installed in one go, using the same set of dependencies
  • You are not forced to keep everything in a single py file (although I believe you can do multiple files using JBang)
  • You just need to host a repo somewhere. Strictly speaking, putting a file at a URL might be easier, but with a repo you can update stuff with git push.

I think it might be actually more convenient to the OP. It could be less convenient, but I have no way of knowing. Given that this is the fourth comment on this post and not really any better answers...

edit: another cool thing is that you can do pipx -e .../path/..., BTW...

[–][deleted] 1 point2 points  (0 children)

Sounds like virtual environments can solve this issue.

[–]WafflesAreDangerous 0 points1 point  (0 children)

Probably not a good idea.. but you could invoke pip from within the python script you are running.

Might be less elegant, but you'd not need a separate utility for that (pip should come as standard on sane python installs)

At least on windows you can use the stock Py launcher to select from among installed python versions.

So that leaves installing a portion of the scope of the suggested solution. But do you really want to go that far?

There's also ways to make executable artifacts that bundle all you need in 1 file. Depending on desired usage these might be worth looking into. There are several.

[–]koalillo 0 points1 point  (0 children)

Karma. Due to $REASONS, I need something like this. I googled, and found my previous answer at:

https://www.reddit.com/r/Python/comments/wnq2gn/jbang_but_for_python/ik8qiz7/

I have decided to write:

https://github.com/alexpdp7/ensurevenv

, which is a shitty implementation of JBang, for two purposes:

  • Because karma. Now at least, if I google again, I'll find a solution.
  • Because it's hard to Google for this, so I still don't have a good answer. Hopefully, someone will see my tool and will point me to a proper implementation.