views:

922

answers:

4

My application looks like this:

main.py
windows/
    __init__.py
    mainwindow.py
    ...
model/
    __init__.py
    orders.py
    ...
resources/
    image1.png
    logo.jpg
    ...

The program is started with main.py. Is there a good way to create a 'final' application out of it? I'm thinking of something like py2exe/py2app, but without copying the python interpreter / modules into the application where one has only one executable.

I had a look at distutils, but this looks like it installs a program into the Python directory, which isn't usual on non-linux platforms.

At the moment I just copy the whole source folder onto the target machine and create an alias to main.pyw on windows. Some inconveniences:

  • The icon is the default python icon.
  • I have to create the alias manually.
  • In my source directory there are a lot of additional files like the source control folder.
  • I have to rename main.py to main.pyw manually.
  • It would be nice if only `.pyo* files are on the target machine. There's no real reason for it, I just don't like having unnecessary files.

How does one create a nice automated distribution?

  • for windows? (That's the only platform that I have to support at the moment.)
  • for mac?
  • for linux?
+7  A: 

The normal way of distributing Python applications is with distutils. It's made both for distributing library type python modules, and python applications, although I don't know how it works on Windows. You would on Windows have to install Python separately if you use distutils, in any case.

I'd probably recommend that you distribute it with disutils for Linux, and Py2exe or something similar for Windows. For OS X I don't know. If it's an end user application you would probably want an disk image type of thing, I don't know how to do that. But read this post for more information on the user experience of it. For an application made for programmers you are probably OK with a distutils type install on OS X too.

Lennart Regebro
Mac and linux are not that important at the moment. Py2app makes .app bundles. And I think that shipping mac apps in .dmg is outdated, one should use .zip. Is it possible to use distutils to just create a directory `dist` and copy all relevant files into that?
Georg
@gs: the sdist command will create a tar file of all source files.
Martin v. Löwis
@gs: Shipping Mac apps in .dmg is actually extremely common. .dmg's are disk images, and not a format for applications (that would be .app). Thus, you often find a single .app inside a .dmg, along with some README file.
EOL
@gs I don't know why you want distutils to just make a directory dist and copy the files there, you can do that yourself. Distutils does a lot of things, including making windows installers, and from Python 2.6 also create links in the Start-menu. It will require you to install Python separately though, so for an end-user app, I think py2exe is a better solution, *because* it includes it's own Python. Shipping/installers for OS X is discussed in detail by Alexander Limi in his bloggpost, so I defer to him.
Lennart Regebro
A: 

If you are distributing on windows, use an installer to install all the relevant files/interpeter whatever is needed. Distribute a setup.exe. That is the best way on windows. Otherwise users will complain.

Byron Whitlock
I don't need an installer because there is only one user who is going to use the program. But of course when writing a program for more users that is a must-have on windows.
Georg
@gs: Oh, only one user. Fine, then I would recommend making a basic distutils package, either a source distribution or a windows binary installer. That's definitely an easy and nice way to distribute a Python module.
Lennart Regebro
+6  A: 

I highly recommend Pyinstaller, which supports all major platforms pretty seamlessly. Like py2exe and py2app, it produces a standard executable on Windows and an app bundle on OS X, but has the benefit of also doing a fantastic job of auto-resolving common dependencies and including them without extra configuration tweaks.

Also note that if you're deploying Python 2.6 to Windows, you should apply this patch to Pyinstaller trunk.

You indicated that you don't need an installer, but Inno Setup is an easy to use and quick to setup choice for the Windows platform.

Daniel
Overkill for this case, as he has only one user, but a good recommendation generally of a software i forgot existed. +1
Lennart Regebro
I'm not sure that it is overkill. Bundling an app with Pyinstaller can actually be easier than other methods, especially those with dependencies on c extensions... as simple as a one line command-line call in most cases. Installing Python + dependencies + the app itself (whether through distutils, etc, or just a zip file) is more involved, especially if the developer isn't able to manually configure the target machine himself and needs to provide instructions to the client.At least on Windows, I think that style of distribution makes sense.
Daniel
A: 

Fredrik Lundh's squeeze.py can create a single file that does not contain the Python interpreter, but instead contains bytecode. With the right arguments, you can include other files, modules, etc. in the result file. I used it successfully in one project. The resulting program ran on OS X, Linux and Windows without any problem!

EOL
Looks very promising, I'll have a look at it.
Georg