Have pip report message to user for further needed action

How to send a message to the user when they should take further action themselves?

For example I have a package whose dependencies can be safely installed on Windows with pip install mypackage but on Linux the platform package manager should be used to complete the dependencies with an apt or yum install thing. Is there an idiomatic something to be added to setup.py for this circumstance or do I roll my own, such as:

#setup.py#
from sys import platform
if platform == "linux" or platform == "linux2":
    print(linux_extra_instructions)

?

1 Like

Printing directly from setup.py as in your example code is currently the only viable option for reporting messages to the user upon installation, but it comes with the following drawbacks:

  • It only works when installing with python setup.py install, which is deprecated. If the package is installed via a wheel like a normal package, the message won’t show up.

  • setuptools already produces a screenful of output on installation, so your message is likely to not get noticed by the user unless you style it obnoxiously.

I believe the preferred way to convey details about installation instructions to the user is to put them in your package’s README/long description instead of in setup.py.

1 Like

Or detect it on load and fail with a detailed error message then.

That’s also helpful for situations where the person running it isn’t the one who did the install (maybe they got a pre-extracted bundle or similar).

(In case you were considering it, don’t trigger the download/install automatically. :slight_smile: )

1 Like

Thanks for the feedback. It’s helped me decide the best thing to do in this case is: nothing! Nothing new that is, just wait for people to try to use function X and then emit a (hopefully) helpful message when the required dependency isn’t found.

1 Like