20

Python's setuptool has two ways of adding command line scripts to a Python package: script and entry_point.

This tutorial outlines these ways:

scripts

Add a Python script (funniest-joke) to the package tree, and add its path to setup.py:

setup(
    ...
    scripts=['bin/funniest-joke'],
    ...
)

Entry point:

Add a Python script (funniest-joke) to the package tree. Add a main() function to it, and add command_line.py submodule which runs funniest's main():

command_line.py:

import funniest

def main():
    print funniest.joke()

setup.py

setup(
    ...
    entry_points = {
        'console_scripts': ['funniest-joke=funniest.command_line:main'],
    }
    ...
)

What are the advantages and disadvantages of each method?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Adam Matan
  • 128,757
  • 147
  • 397
  • 562
  • 11
    possible duplicate of [Difference between entry\_points/console\_scripts and scripts in setup.py?](http://stackoverflow.com/questions/18787036/difference-between-entry-points-console-scripts-and-scripts-in-setup-py) – Wayne Werner Sep 17 '14 at 13:12

1 Answers1

7

Basically scripts is the old way which requires you to have a stand-alone, executable script file and the entry-points method lets you define which functions you want to run when a command is given. This way you can have several functions in the same file/module and then have 'entry points' which will be called when the user types in one of the console_scripts commands.

Although setup() supports a scripts keyword for pointing to pre-made scripts to install, the recommended approach to achieve cross-platform compatibility is to use console_scripts entry points (see below).

From https://packaging.python.org/tutorials/distributing-packages/#scripts (old source)

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
Cargo23
  • 3,064
  • 16
  • 25