Search code examples
pythonpython-3.xsetuptoolspython-packagingpython-wheel

Create a python package and after install use like a executable


I am working on a script and I would like to use like an executable. That means I wanna install with pip and run with its name. example:

pip install myscript.whl
myscript

I am already created a whl file (via 'python setup.py bdist_wheel'), however I am not sure what is the next step. How can I do that after pip install an executable automatically created and can be used from anywhere in powershell or linux terminal.


Solution

  • Since you already have a setup.py, all you need to do is follow the steps outlined in the Packaging Guide to set up a console script entry point.

    setup(
        ...
        entry_points = {
            'console_scripts': ['myscript=myscript.some_module:some_function'],
        }
        ...