The ExeMaker Tool
Updated October 12, 2004 | October 10, 2004 | Fredrik Lundh
“Outstanding utility. It isn’t just neat, it’s indispensable. ”
ExeMaker is a small tool that takes a Python script, copies it to a program directory, and creates a Windows EXE file in the same directory. When you run that EXE, it automatically runs the script. To see how it works, let’s look at an example:
> exemaker pythondoc.py c:/bin c:/bin/pythondoc.exe ok c:/bin/pythondoc.py ok
> dir c:\bin\pythondoc* 2004-10-10 15:00 4 096 pythondoc.exe 2004-10-10 15:00 41 611 pythondoc.py 2 File(s) 45 707 bytes
Assuming that c:/bin is on your path, you can now run the script as a normal command-line tool:
> pythondoc PythonDoc 2.1b3 (c) 2002-2003 by Fredrik Lundh. Usage: pythondoc [options] files... ...
In other words, ExeMaker lets you install command-line programs written in Python along with other utilities, and use them without having to bother with PY associations, BAT files, or other workarounds. Your programs will also show up in the task manager under their real names.
Usage #
Syntax:
exemaker [-i interpreter] script [directory]
Copies the script to the directory, and adds an EXE loader to the same directory. If the directory is omitted, the script is copied to the directory where exemaker itself is installed.
The -i option can be used to control what Python EXE or DLL to use to run the program. If omitted, it defaults to python.exe. Note that the EXE loader doesn’t actually use the EXE to run the script; it just checks what Python DLL it uses, and loads that DLL directly. For more information, see the Details section below.
Details #
The ExeMaker tool creates two files based on the given script; one EXE file and one PY file. The EXE file contains a small runtime loader, and the PY file is simply a copy of the script, with a small header attached to the top. The header is used by the EXE loader to figure out how to run the PY file. It usually looks like this:
#!python.exe import site ... your script follows ...
The #! line is used by the EXE loader to locate the right Python DLL. If the line contains an EXE file, it is inspected to see what Python DLL it uses, and that DLL is then used to run the script. If the line contains a DLL file, that DLL is used directly.
The default is to use the current Python executable (python.exe). You can override this by using the -i option, or by editing the #!-line in the generated PY file.
The following formats can be used for the #! line:
format (example) | search path |
---|---|
#!python.exe | Search for python.exe along the PATH, and check what Python DLL it uses. Search for that DLL along the PATH. |
#!/path/python.exe | Look for python.exe at the given location, and check what Python DLL it uses. Look for that DLL in the same directory as the EXE. If not found, search for the DLL along the PATH. |
#!python24.dll | Search for python24.dll along the PATH. |
#!/path/python24.dll | Look for python24.dll at the given location. |
(no #! line) | Same as #!python.exe. |
Downloads #
ExeMaker can be downloaded from the effbot.org downloads section.
To use, just unpack the archive and put exemaker.exe and exemaker.py in a directory somewhere on your path.
The current version has been tested with Python 2.1 and newer. If you need support for older versions, let me know.