+7  A: 

See the distutils simple example. That's basically what it is like, except real install scripts usually contain a bit more information. I have not seen any that are fundamentally more complicated, though. In essence, you just give it a list of what needs to be installed. Sometimes you need to give it some mapping dicts since the source and installed trees might not be the same.

Here is a real-life (anonymized) example:

#!/usr/bin/python 

from distutils.core import setup 

setup (name = 'Initech Package 3', 
          description = "Services and libraries ABC, DEF", 
          author = "That Guy, Initech Ltd", 
          author_email = "[email protected]", 
          version = '1.0.5', 
          package_dir = {'Package3' : 'site-packages/Package3'}, 
          packages = ['Package3', 'Package3.Queries'], 
          data_files = [ 
                       ('/etc/Package3', ['etc/Package3/ExternalResources.conf']) 
          ])
Sander
+1  A: 

Most Python programs will use distutils. Django is a one - see http://code.djangoproject.com/svn/django/trunk/setup.py

You should also read the documentation, as it's very comprehensive and has some good examples.

Andrew Wilkinson
A: 

@Andrew That's part of the problem... it's a bit too comprehensive. I'm not sure I (or many other people) want to read a novel on distutils just to package up 500 lines of code.

Jiaaro
+1  A: 

distutils really isn't all that difficult once you get the hang of it. It's really just a matter of putting in some meta-information (program name, author, version, etc) and then selecting what files you want to include. For example, here's a sample distutils setup.py module from a decently complex python library:

Kamaelia setup.py

Note that this doesn't deal with any data files or or whatnot, so YMMV.

On another note, I agree that the distutils documentation is probably some of python's worst documentation. It is extremely inclusive in some areas, but neglects some really important information in others.

Jason Baker
A: 

@Jason

so how do you roll a .deb file using the setup.py if it doesn't include datafiles?

Jiaaro
A: 

so how do you roll a .deb file using the setup.py if it doesn't include datafiles?

Building a Debian package is relatively easy if you have a setup.py written -- you can use the standard Python package helpers. Take a look at existing small Python libraries like cjson.

However, since it's rather difficult to get a small-time projected included in a main repository, it might be easier for you to upload your package to the Python Package Index. Then installation is just an easy_install away.

John Millikin
A: 

@John Millikin - I've found that it's not that hard to get a package into the Ubuntu repos as long as it's clearly useful and not buggy. Especially if it's a GUI app.

Sometimes the bugginess doesn't even matter either ;)

Jiaaro
A: 

That's part of the problem... it's a bit too comprehensive. I'm not sure I (or many other people) want to read a novel on distutils just to package up 500 lines of code.

You don't need to. The simple example posted is sufficient to package your library.

so how do you roll a .deb file using the setup.py if it doesn't include datafiles?

You write a setup.py, using Sander's example. That will conclude the distutils part of your installer. Then, read the Ubuntu packaging guide, adapting as needed if you use Debian instead. Making a .deb is significantly harder, in my experience, than writing setup.py.

John Millikin
A: 

Hello I have a doubt about installing packages using distutils. I think after running:

python setup.py install

All the files for my package will be installed in the system python location for 3rd party modules. But there is any way to install modules in my HOME folder. In many facilities you can only install stuff in your $HOME folder, so would be nice to have a way to install modules using distutils in my $HOME folder. Thanks

Pablo Gimenez
hello! welcome to stack overflow. You should post this as a new question (the big "Ask Question" button on the top right) so the community will see it and answer it. I'm the only person who will be notified when you post answers here.
Jiaaro
Thanks Jiaaro. First time using Stack Overflow :)
Pablo Gimenez