[Pythonmac-SIG] Building plans .....

Berg, Stuart bergs at janelia.hhmi.org
Thu Mar 12 14:42:56 EDT 2020


(I haven’t been following this thread too closely, so sorry in advance if the following is not exactly what you’re looking for.)

FWIW, I’ve shipped .app bundles using conda and py2app for years.*  I don’t have time to write up a minimal example, but I can provide links to the scripts we use.

It’s a little bit of a hack, but it’s not complicated.


  1.  First, create a conda environment that contains your application and all of its dependencies.
  2.  Run py2app in “alias mode”[1]. Alias mode creates a mostly-empty bundle that merely links to an external python installation.  It’s intended for development, but we can exploit it for our purposes. On my project, we use a special setup.py script for this.[2]
  3.  Move the entire conda environment into the .app bundle directory.  There’s no need to change the directory structure.
  4.  Since the .app bundle was pointing to that environment, you need to find/replace the internal links that py2app wrote within your .app bundle.  Instead of pointing to the external conda environment, they should point to the now-internal environment (with relative paths, of course).  It amounts to a few sed commands and symlinks.[3]

Note: Although you moved the conda environment, there should (usually) be no need to replace any paths within the conda environment directory itself.  Unless you’re doing something weird, most conda environments use purely relative links internally, and are thus fully relocatable.  For example, our application is based on the standard scientific python stack (numpy, pandas, skimage, etc.), with lots of other dependencies, too.  If it works for us, it probably works for most people.

If you want to see what the final bundle will look like, try downloading the current version of ilastik[4]. (Sorry, it’s a heavy download – it’s based on a big conda environment, with ~120 packages.)

Maybe there are better ways of doing this, but I settled on this method without really needing to understand exactly what py2app is really doing.  And plus, it leaves your conda environment completely intact.  For instance, you can inspect it with “conda list -p ilastik.app/Contents/ilastik-release”, or even install additional packages after-the-fact.

Best,
Stuart

*I don’t work on the ilastik project any more, but I’m pretty sure the current team still uses this procedure.

[1]: https://py2app.readthedocs.io/en/latest/tutorial.html#development-with-alias-mode
[2]: https://git.io/Jv6VG
[3]: https://git.io/Jv6Vl
[4]: https://www.ilastik.org/download.html



From: Pythonmac-SIG <pythonmac-sig-bounces+bergs=janelia.hhmi.org at python.org> on behalf of Christopher Barker <pythonchb at gmail.com>
Date: Thursday, March 12, 2020 at 12:26 PM
To: Just van Rossum <justvanrossum at gmail.com>
Cc: Jack Jansen <Jack.Jansen at cwi.nl>, Pythonmac-Sig <Pythonmac-SIG at python.org>
Subject: Re: [Pythonmac-SIG] Building plans .....

On Wed, Mar 11, 2020 at 11:48 PM Just van Rossum <justvanrossum at gmail.com<mailto:justvanrossum at gmail.com>> wrote:
FWIW, as far as I can tell, a non-framework-build can't be used to build a native macos app, at least not with py2app.

I'm pretty sure it can. We've moved to PyInstaller, which does work, and I'm'pretty sure that py2app can work with conda's non-Framework build.

and it's on conda-forge, so presumably it's worked for at least one person :-)

https://anaconda.org/conda-forge/py2app<https://urldefense.com/v3/__https:/anaconda.org/conda-forge/py2app__;!!Eh6p8Q!VrzDuyXDlgxXw6SuvHF-vk_iAfL0Cl5PlPk5QD3NMR-hC7BhfmF-eaYhR_fDk6EgBQ$>

I do recall some issues a while back that have presumably been resolved.

I ran into this while trying to build an app on github-actions, and had to resort to downloading and installing Python from python.org<https://urldefense.com/v3/__http:/python.org__;!!Eh6p8Q!VrzDuyXDlgxXw6SuvHF-vk_iAfL0Cl5PlPk5QD3NMR-hC7BhfmF-eaYhR_dlML8dSQ$> upon build. Which is wasteful, and in my eyes completely unnecessary.

https://github.com/actions/setup-python/issues/58<https://urldefense.com/v3/__https:/github.com/actions/setup-python/issues/58__;!!Eh6p8Q!VrzDuyXDlgxXw6SuvHF-vk_iAfL0Cl5PlPk5QD3NMR-hC7BhfmF-eaYhR_dcg4q17Q$>

I'm sad to learn conda does the same as it renders its Python completely useless for my work.

Actually, perhaps conda would work for you :-) I'm not clear on what gitHub actions allows, but you can certainly use conda on, e.g. TravisCI with OS-X. I've only used it to run tests, but I can't see why you couldn't build a app that way.

By the way, it's great to "see" all you from back in the day -- this has been a very quiet list lately!

-CHB


--
Christopher Barker, PhD

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythonmac-sig/attachments/20200312/f2ebe406/attachment-0001.html>


More information about the Pythonmac-SIG mailing list