Packaging your python scripts.

Oh hi there! Welcome to another useful post. This post is going to be about how to package your python scripts and packages for distribution on PyPI or some other place. Here I won’t go too deep into explaining everything as most of us just need to know the basics of packaging. However i will provide you with different links for further study. Okay lets talk about

>>> setuptools

first. What is it ? It’s a Python module which allows us to easily package our python scripts and modules for distribution. However there are other packaging libraries as well but here i will talk about setuptools only.

So what should be the basic example to show the usage of setuptools ? Here you go. For basic use of setuptools, just import things from setuptools and then look below for the minimal setup script using setuptools.

from setuptools import setup, find_packages
    name = "HelloWorld",
    version = "0.1",
    packages = find_packages(),

As you see we don’t have to specify much in order to use setuptools in a project. Just by doing the above, this project will be able to produce eggs, upload to PyPI, and automatically include all packages in the directory where the lives. But when you are releasing your projects on PyPI then you should add a bit more information about yourself and this package and if your project relies on some external dependencies then list them there as well. Here is another script which can do all that :

from setuptools import setup, find_packages
    name = "HelloWorld",
    version = "0.1",
    packages = find_packages(),
    scripts = [''],

    # Project uses reStructuredText, so ensure that the 
    # docutils get installed or upgraded on the target 
    # machine
    install_requires = ['docutils>=0.3'],

    package_data = {
        # If any package contains *.txt or *.rst files,
        # include them:
        '': ['*.txt', '*.rst'],
        # And include any *.msg files found in the 
        # 'hello' package, too:
        'hello': ['*.msg'],

    # metadata for upload to PyPI
    author = "Me",
    author_email = "",
    description = "This is an Example Package",
    license = "PSF",
    keywords = "hello world example examples",
    # project home page, if any :
    url = "",   

    # could also include long_description, download_url,
    # classifiers, etc.

I hope this is enough for now. However here are some other packaging libraries in case you were wondering :

1. Distutils is the standard tool used for packaging. It works rather well for simple needs, but is limited and not trivial to extend.

2. Setuptools is a project born from the desire to fill missing distutils functionality and explore new directions. In some sub-communities, it’s a de facto standard. It uses monkey-patching and magic that is frowned upon by Python core developers.

3. Distribute is a fork of Setuptools that was started by developers feeling that its development pace was too slow and that it was not possible to evolve it. Its development was considerably slowed when distutils2 was started by the same group.

4. Distutils2 is a new distutils library, started as a fork of the distutils codebase, with good ideas taken from setup tools (of which some were thoroughly discussed in PEPs), and a basic installer inspired by pip. Distutils2 did not make the Python 3.3 release, and it was put on hold.


For further study i recommend:


2 thoughts on “Packaging your python scripts.

  1. Pingback: Packaging and distributing your python libraries | Bite Sized Python Tips

  2. Somehow it is not working for me. Here is the error

    “usage: [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] …]
    or: –help [cmd1 cmd2 …]
    or: –help-commands
    or: cmd –help

    error: no commands supplied is the name of the file storing above code.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s