Search code examples
pythonpipwarningssetuptools

Print a message from setup.py through Pip


Is there any way to make a message and/or warning visible to the user from setup.py when they use pip?

My package makes use of a custom install command. The structure of the setup.py is like this:

from setuptools import setup
from setuptools.command.install import install
import warnings
import sys


class CustomInstallCommand(install):
    def run(self):
        install.run(self)
        sys.stdout.write('My message.\n')
        sys.stdout.flush()
        warnings.warn('My warning.', UserWarning)


setup(name='blub',
      version='0.1',
      description='blah',
      packages=['blub'],
      cmdclass={'install': CustomInstallCommand})

When I run python setup.py install, I see the custom print message and the warning in the output.

However, if I run pip install ., I only get this:

C:\Users\ae\Software\SomeModule>pip install .
Processing c:\users\ae\software\somemodule
Building wheels for collected packages: blub
  Building wheel for blub (setup.py) ... done
  Created wheel for blub: filename=blub-0.1-cp37-none-any.whl size=1115 sha256=51c91c5b449673e3be5dd7382cd12f59cb38021167ba3a0b3634214419c61bcb
  Stored in directory: C:\Users\ae\AppData\Local\Temp\pip-ephem-wheel-cache-575zecpf\wheels\81\5f\73\46e55517a1e0973939e9578945ff104b6e0193cfaed649e206
Successfully built blub
Installing collected packages: blub
  Found existing installation: blub 0.1
    Uninstalling blub-0.1:
      Successfully uninstalled blub-0.1
Successfully installed blub-0.1

Solution

  • Try: pip install . -v

    -v is verbose, it shows the verbose messages. It is close by default. Users do not want to see it. If you display it like an error they might be but it can be confused for them if it not an error and you display it as an error.

    Link for further help: How to print warnings and errors when using setuptools (pip)