I want to add another scenario that I ran into but isn't explicitly stated here:
Your CLI name can be different from your entry point, which can mean you'll need to provide the name explicitly if importlib_metadata can't automatically find the name
Error
Without package_name='my_command_line_interface'
:
mycli --version
RuntimeError: 'mycli' is not installed. Try passing 'package_name' instead.
Setup
setup.py
setup(
name='my_command_line_interface',
version='0.1',
py_modules=['application'],
install_requires=[
'Click',
],
entry_points="""
[console_scripts]
mycli=my_command_line_interface.cli:cli
""",
)
cli.py
@click.group()
@click.version_option(package_name='my_command_line_interface') # <-- ADDED
@click.pass_context
def cli(ctx):
pass
__main__.py
from .cli import cli
if __name__ == "__main__":
cli()