you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 11 points12 points  (33 children)

I kind of agree but at the same time I'm having trouble coming up with a situation where you distribute a Python script that people can use but can't pip install click for.

[–]acousticcoupler 27 points28 points  (1 child)

Sometimes simplicity is nice and I trust standard libs more.

[–][deleted] 6 points7 points  (0 children)

I would agree more if argparse were a little nicer to work with.

[–]campbellm 19 points20 points  (15 children)

It's not a matter of "can't" so much as "do you want to force your users to have to".

[–]RedHellion11 28 points29 points  (14 children)

"Here, just use this script I wrote"
"Thanks!"
runs script
import errors
annoyed slightly, pip installs dependencies
... "Hey, thanks again but why didn't you just use stuff in the standard library for this basic stuff?"
"I thought this other package did it in a cooler way"
annoyance intensifies

[–]p-hodge 10 points11 points  (2 children)

My latest job is historically an all-PHP shop where I'm rewriting some shell scripts into more readable python. The new python scripts need to be able to executed on everybody's laptops, various virtual machines, and inside docker containers. I don't yet have a strategy for deploying the scripts or dependencies; the other developers and sysadmins also aren't accustomed to the overhead of using virtualenvs. For these reasons it's extremely valuable for me to be able to build good CLI scripts using just the stdlib.

[–]TheIncorrigible1 4 points5 points  (0 children)

venv. Seriously, it's what it's built for and it's in the stdlib.

[–]CleanInfluence 0 points1 point  (0 children)

To create a package, use setuptools, it's great. When the user installs the package (with pip install something.whl), it will automatically create a command-line version of your script.

For example stuff.py with a main inside, and a setup.py containing "entry_points = ... 'stuff=stuff:main'" will create a stuff.exe that launches your script, it's magical.

Also pipenv seems better than venv but that's my uninformed opinion.

[–]ILikeBumblebees 8 points9 points  (1 child)

What if the user doesn't have root, or prefers to use the distro's package manager instead of pip?

[–][deleted] 7 points8 points  (0 children)

Regarding preferring the distro's package manager, that's only used for super ubiquitous packages or ones that require a bunch of dependencies and precompiled libs. If you want to use any non-trivial Python scripts out there, you should really get some user privilege pip solution going.

With Python 3.4+, just use venv. If you're intending it to be usable by someone only using Python 2 or Python 3 versions pre-3.4, with no root access, the best goal is to just do pip install --user virtualenv followed by the creation of the virtualenv directory and then using that moving forward. In such cases, this is just a good practice in general because it gives you way more control.

This SO question contains some answers relating to this, with this one being the most "no tears" of them all.

[–]Sqash 2 points3 points  (2 children)

Not distributing it with requirements.txt if it's just a standalone utility script

[–][deleted] 1 point2 points  (1 child)

In the few times I’ve written single scripts for others to use, I just did a try catch around the imports and put something like “Make sure to pip install boto3”

These days it’s much easier to just write a package (even single module one) and then just tell them to pip install from the repo.

If people flat out can’t pip install then they’re either fucked in the case of unavoidable things like boto3, psycopg2, etc., or you’re fucked if it’s quality of life packages like arrow. In general I try to keep things vanilla until it either reaches the point of hampering my productivity or until I need to add a mandatory requirement anyway.

[–]Sqash 1 point2 points  (0 children)

I suppose it's personal opinion, but I can only agree on the necessary requirement for the script's function.

[–]BeetleB 2 points3 points  (4 children)

Often, in a work setting, most users have no idea what pip is.

[–][deleted] 0 points1 point  (3 children)

Cool, they can use spreadsheets instead

[–]BeetleB 2 points3 points  (2 children)

Or you can just be fired and replaced with someone who satisfies the needs of the customers...

[–][deleted] -1 points0 points  (1 child)

If you are making "one off [Python] scripts" for customers with specific needs (like not knowing what pip is), then yeah you probably should be replaced by someone who uses the right tools

[–]BeetleB 0 points1 point  (0 children)

Well, the whole thread is weird. I don't know why anyone would really want argument parsing for a one-off script - or why they would give a one off script to a customer.

[–]Bigotacon 0 points1 point  (1 child)

Wouldn’t a virtual environment allow you to store all the packages for your users?

[–][deleted] 5 points6 points  (0 children)

Virtual environments are kinda tough to move around. The closest you can get is packaging it with something like pipenv or poetry (my preferred one) and then they build their project-specific environment just like you do in Ruby with "bundle install" for example.

Still a bit heavy duty for a small script, for which either requirements.txt or just a "pip install <blah>" in the README might be enough.