How can I use setuptools to generate a console_scripts entry point which calls `python -m mypackage`? How can I use setuptools to generate a console_scripts entry point which calls `python -m mypackage`? python python

How can I use setuptools to generate a console_scripts entry point which calls `python -m mypackage`?


How can I use entry_points to generate a binary that calls python -m mypackage (and passes *args, **kwargs) ?

I think this is the wrong way to look at the problem. You don't want your script to call python -m mypackage, but you want the script to have the same entry point as python -m mypackage

Consider this simple example:

script_proj/├── script_proj│   ├── __init__.py│   └── __main__.py└── setup.py

and the minimalistic setup.py:

from setuptools import setupsetup(    name="script_proj",    packages=["script_proj"],    entry_points = {        "console_scripts": [            "myscript = script_proj.__main__:main",        ]    })

__main__.py is a dummy module and contains the main method.

def main():    print("Hello world!")if __name__ == "__main__":    main()

After installing, you have the executable myscript, which calls the main method in __main__.py.In this package design python -m script_proj also calls the same main method.