Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Python distutils?

Tags:

I wrote a quick program in python to add a gtk GUI to a cli program. I was wondering how I can create an installer using distutils. Since it's just a GUI frontend for a command line app it only works in *nix anyway so I'm not worried about it being cross platform.

my main goal is to create a .deb package for debian/ubuntu users, but I don't understand make/configure files. I've primarily been a web developer up until now.

edit: Does anyone know of a project that uses distutils so I could see it in action and, you know, actually try building it?

Here are a few useful links

  • Ubuntu Python Packaging Guide

    This Guide is very helpful. I don't know how I missed it during my initial wave of gooling. It even walks you through packaging up an existing python application

  • The Ubuntu MOTU Project

    This is the official package maintaining project at ubuntu. Anyone can join, and there are lots of tutorials and info about creating packages, of all types, which include the above 'python packaging guide'.

  • "Python distutils to deb?" - Ars Technica Forum discussion

    According to this conversation, you can't just use distutils. It doesn't follow the debian packaging format (or something like that). I guess that's why you need dh_make as seen in the Ubuntu Packaging guide

  • "A bdist_deb command for distutils

    This one has some interesting discussion (it's also how I found the ubuntu guide) about concatenating a zip-file and a shell script to create some kind of universal executable (anything with python and bash that is). weird. Let me know if anyone finds more info on this practice because I've never heard of it.

  • Description of the deb format and how distutils fit in - python mailing list

like image 984
Jiaaro Avatar asked Aug 27 '08 05:08

Jiaaro


People also ask

What does Distutils do in Python?

The distutils package provides support for building and installing additional modules into a Python installation. The new modules may be either 100%-pure Python, or may be extension modules written in C, or may be collections of Python packages which include modules coded in both Python and C.

How do I run Python setup py?

To install a package that includes a setup.py file, open a command or terminal window and: cd into the root directory where setup.py is located. Enter: python setup.py install.

How do I call a package in Python?

First, we create a directory and give it a package name, preferably related to its operation. Then we put the classes and the required functions in it. Finally we create an __init__.py file inside the directory, to let Python know that the directory is a package.

What is Python Setuptools used for?

Setuptools is a package development process library designed to facilitate packaging Python projects by enhancing the Python standard library distutils (distribution utilities). Essentially, if you are working with creating and distributing Python packages, it is very helpful.


2 Answers

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'])            ]) 
like image 166
Sander Avatar answered Oct 01 '22 22:10

Sander


apt-get install python-stdeb

Python to Debian source package conversion utility

This package provides some tools to produce Debian packages from Python packages via a new distutils command, sdist_dsc. Automatic defaults are provided for the Debian package, but many aspects of the resulting package can be customized via a configuration file.

  • pypi-install will query the Python Package Index (PyPI) for a package, download it, create a .deb from it, and then install the .deb.
  • py2dsc will convert a distutils-built source tarball into a Debian source package.
like image 45
Stuart Cardall Avatar answered Oct 01 '22 23:10

Stuart Cardall