Distributing Unix applications

Supporting your application is usually a simple task once you have access to a built Python and Tcl/Tk. In general, UNIX end users are capable of building and installing both of these so you may be able to simply require your end users to take care of them. Then your application installation may be as simple as extracting files from a tar file and editing the users' environments appropriately. For the moment, let's assume that this is the case, so we will concentrate on getting your application up and running.

First, we need an executable to start your application. Our aim here is to use a minimal Python script to get into your application's main module (remember that a Python script will be interpreted every time you invoke it, so you want to keep the script simple; see "Everyday speedups" on page 348).

Here is an example of a minimal script:

#!/usr/bin/env python import myapplication myapplication.main()

There are some cases where you cannot use # ! /usr/bin/env python, so you might have to give an explicit path such as /usr/local/bin/python. One small reminder: the space in the first form is meant to be there; it is not uncommon for UNIX folks to unconsciously translate the space into a slash. Next, you might need to add a little bit more to make this work. The script assumes that the environment variable PYTHONPATH has been set and it includes paths to .../Python/Lib and wherever MyApplication.py is installed. You may not want to modify the user's environment, but you can do that within your script:

#!/usr/bin/env python import sys sys.path.insert(0, '/opt/yourapp/lib')

import myapplication myapplication.main()

Clearly some refinements can be made, but this scheme works well in practice.

0 0

Post a comment

  • Receive news updates via email from this site