سؤال

Distutils offers existing solutions to build a Windows self-extracting EXE. Notably, I can create the package even if I'm on Ubuntu (which is essential given our automated build process).

How do I build an osx installer from an Ubuntu machine?

(This is for python 2.7)

هل كانت مفيدة؟

المحلول

You could do the following, since OS X has a UNIX foundation. (I'm assuming it also has some standard utilities like uudecode and unzip.);

  • Create a zipfile for your package with the standard Python packaging tools, like distutils.
  • Use uuencode file.zip file.zip >uu.txt to convert this zip-file to text.
  • Create a shell-script.
  • Put the text generated by uuencode as a here-document in that shell-script, that is fed to uudecode, to recreate the zipfile. This should be the second command in the shell-script. The first commands should check for neccesary utilities.
  • Use whatever Python setup tools you have to install the zipfile.
  • Do any post-install stuff you want.
  • Remove the zip-file.

To install the program, run the shell-script. On UNIX, this script should be run as root. Don't know how OS X handles that, though. Below is an example (the included zipfile contains two files with only random noise) ;

#!/bin/sh
# Install script for foo

# Check for special programs that are used in this script.
PROGS="uudecode unzip python"
for P in $PROGS; do
    which $P >/dev/null 2>&1
    if [ $? -ne 0 ]; then
        echo "$(basename $0): The program \"$P\" cannot be found."
        exit 1
    fi
done

uudecode <<"EOF"
begin 644 test.zip
M4$L#!`H``````(<!K$`````````````````$`!P`9F]O+U54"0`#OHZM3ZB.
MK4]U>`L``03I`P``!.D#``!02P,$"@``````A`&L0$EXM>H``@````(```<`
M'`!F;V\O8F%R550)``.XCJU/N(ZM3W5X"P`!!.D#```$Z0,``)DCNBVSM81_
MA%IQ!+LKC\;\19[/E]F!`J2J*2:9B_8#MC^KM*]]9P1]?1Y1@1+/H%Q"'2J'
M,;$7:C9E+WC]%M(BAUFN]4D\$%F63!^CA8O>'0C(-!YD?$\GQ[;M:?@>=A/[
M61XK<A/]\.?!0$QX<5]T\9<ZP$;_?PRMV-3O(NK)/<MTI,!RYA&OWRK6<8%4
M_1!T/+-'7H^V#C[AK)+U?T>UCU."G]D(+JU[8Z#1EI89@'^10B:8.2$$9Q*@
MY:L4MK'^TVF)A5)9\%"/FF+1T@;]8\,I)$CCHHF#E&,D.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-L:^FD/24Q)S*-D8)Z>F4Y^+$]\_'
MB\$$;#D__S_RT(Y]MMK?B#%F1&C`>,)'7:12DX=F)T,/!*^(M*[,^N;6E4";
M31K\AG0@[@4L9MB.`1Z!`%@K5G)P<]0!?P\$RFUC/S:Y_Y\0*:\+$U+JEM%"
M9E!+`0(>`PH``````(<!K$`````````````````$`!@`````````$`#M00``
M``!F;V\O550%``.^CJU/=7@+``$$Z0,```3I`P``4$L!`AX#"@``````A`&L
M0$EXM>H``@````(```<`&````````````*2!/@```&9O;R]B87)55`4``[B.
MK4]U>`L``03I`P``!.D#``!02P$"'@,*``````"&`:Q`Q2@K\@`"`````@``
M!P`8````````````I(%_`@``9F]O+V)A>E54!0`#O(ZM3W5X"P`!!.D#```$
:Z0,``%!+!08``````P`#`.0```#`!```````
`
end
EOF

# Unpack your zipfile
unzip test.zip
# Go into the created subdirectory and install
cd foo
python setup.py install
# whatever post-install stuff you want goes here...
cd ..
rm -rf foo test.zip

نصائح أخرى

Py2app, cx_freeze, and py2exe are for creating standalone applications, not installers.

You can use Python distutils to create a zip file of your package, and then wrap the zip file in a script that self-extracts and installs the package, like this: http://www.noah.org/wiki/Self-extracting_Python_Script

Or, if you want to create an installer that displays a GUI with a click-through license, then you need OS X PackageMaker to create an mpkg file. I don't think there's a Linux equivalent. If you want to try building an mpkg by hand, try this answer: PackageMaker for creating Mac packages on Windows/Linux

py2app is the Mac counterpart to py2exe, but I don’t know if you can run it from Ubuntu.

pyinstaller can create OSX executables, but I've only used it on OSX myself, so I don't know if it works from Ubuntu.

I learned about this program reading the documentation for kivy, here: http://kivy.org/docs/guide/packaging-macosx.html

I hope some of this is helpful.

You have similar trouble that I suffered with.

On mac. I bet you want use dmg package instead of Installer unless you really need to install driver or some sort of DRM.

So I'll just assume that you want make your .app directory and packaging it as dmg file so that you can distribute your application easily.

To build a .app directory out of python code, you might wanna use Pyinstaller. Pros

  1. It's Cross Platform.
  2. Works good on mac, windows, linux
  3. You can control everything on command line.
  4. It's still actively developing.
  5. It packs required dependencies automatically and doesn't create conflict with installed Python on local machine.
  6. Good Documentation.

Cons

  1. bit of inconsistency between new version and old version.

To build .app using Pyinstaller, here's related document link

and to build dmg file, you can use free options out there, but for me, DMG Canvas was pretty useful.

Pros

  1. support command line
  2. support template (Create pretty background and folders using GUI and reuse it on command line)
  3. support license agreement

Cons

  1. Not Free

As far as I know, there's no unified solution from .py to build .app file and to dmg or installer.

So you should write some code to automatize it, but it's pretty straight forward, since both of them support

Command line.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top