How to package a command line Python script

Zach picture Zach · Jul 12, 2009 · Viewed 11.7k times · Source

I've created a python script that's intended to be used from the command line. How do I go about packaging it? This is my first python package and I've read a bit about setuptools, but I'm still not sure the best way to do this.


Solution

I ended up using setup.py with the key configurations noted below:

setup(
....
    entry_points="""
[console_scripts]
mycommand = mypackage.mymodule:main
""",
....
)

Here's a good example in context.

Answer

Alex Martelli picture Alex Martelli · Jul 13, 2009

@Zach, given your clarification in your comment to @soulmerge's answer, it looks like what you need is to write a setup.py as per the instructions regarding the distutils -- here in particular is how you register on pypi, and here on how to upload to pypi once you are registrered -- and possibly (if you need some extra functionality wrt what the distutils supply on their own) add setuptools, of which easy_install is part, via the instructions here.