perltux has asked for the wisdom of the Perl Monks concerning the following question:

I have a GUI based application written by me in Perl, using Perl-Tk for the GUI. This application runs well on Linux, Windows and macOS (on macOS it requires an installed X11 server for the GUI).

In order to distribute this application to Windows users I packaged it up into an exe file using ParPacker and this works really well, no complaints from the users.

I tried using ParPacker on macOS but ran into problems with X11 and other libraries not being found as their location varies depending on the X11 server installed and depending on which packaging system is being used, there is XQuartz and there are X11 servers in Homebrew and Macports and there are even various distributions of Perl and related modules (the limited Perl included in macOS and the Perl packages from Homebrew and Macports), each using different paths and apparently also different library versions.
It seemed very much a mess to me and even after days of trying I wasn't able to find a satisfactory solution.

So has anybody successfully packaged up a Perl-Tk application for macOS and if yes how exactly did you do it, using ParPacker or some other method?
Any hints would be very helpful. TIA.
  • Comment on How do I package up a Perl-TK app for macOS?

Replies are listed 'Best First'.
Re: How do I package up a Perl-TK app for macOS?
by starX (Chaplain) on Nov 14, 2025 at 17:57 UTC

    I have done this once as an academic exercise, and ran into all of the problems that you are now. The least painful approach was to build / bundle it as a macOS .app file. That involves installing XQuartz so that Tk can compile, building a private perl with perlbrew, and then instaling Tk, cpanm, and PAR_Packer in that private perl. After this, you can use pp to build a self-contained executable, and then use Platypus to build the .app bundle that will execute the pp file.

    If you want to distribute the app, your users will have to install XQuartz manually, but you can write your .app file so that it checks to make sure it is installed, and then prompts the user to install it if they don't have it. The alternative would be to bundle Perl, Tk, and X11 inside of the .app, but I didn't want to do that, so if you try that method, you'll have to let me know how it goes.

      Thanks for the reply, perlbrew definitely sounds interesting, but how does it work in order to build Tk and other Perl modules, are Macports or Homebrew packages still needed for the various FOSS libraries like libjpeg and so on that Tk and other Perl modules depend on or is Perlbrew self contained from this point of view too?

        Obligatory disclaimer that I only used it the one time, so there are some gaps in my knowledge on this, but perlbrew lets you build a private perl environment (or multiple private perl environments) separate from your system perl environment, and everything in that environment is essentially its own sandbox, with its own bin/, lib/, and man./ directories. Any modules need to be installed for the perlbrew environment through cpan inside of perlbrew. Perl/Tk is a wrapper around Tcl/Tk and may reference system libraries (i.e. X11 or image libraries) that are not part of perlbrew, and perlbrew does not provide them.

        In practice, if you install XQuartz, Perl/Tk build scripts should detect X11 headers and libraries installed in /opt/X11 as normal. I believe XQuartz will install libjpeg for you, but if not, installing those through Homebrew or Macports should work. Modules like Tk will compile against the system libraries that they find -- which is something you might have to be careful about if there are multiple instances of those installed on your system.

        The advantage to the perlbrew method was to build an isolated perl environment for the .app bundle that would not rely on the presence of whatever perl environment comes on a mac, which will let you ensure cpan module compatibility for the private environment in your app bundle. But this is why you would want your .app bundle to check for the presence of XQuartz and direct users to install it if they don't have it, as those system resources still need to be installed at the system level.

        SCNR, but if you are lucky the target system has the required tools (compiler etc) to do the module installation, so you might not need to bundle Tk, but could just automagically run the CPAN install when needed. Of course, you could also run the commands to install the compiler first.

        Visual Studio and Android Studio do the same thing, so if anyone asks, you can always say you are following industry standard practices ;-)

        #!/usr/bin/env perl use strict; use warnings; use CPAN; use Module::Load; BEGIN { my @extramodules = ('Tk', 'Net::Clacks::Client'); foreach my $extramodule (@extramodules) { my $firstrun = 1; eval { load $extramodule; $firstrun = 0; }; if($firstrun) { # Run some commands to install required system tools. IDK +macos, so *shrug* # `brew install --yes gcc` print "Installing $extramodule...\n"; CPAN::Shell->install($extramodule); # Tk install runs a lot of tests that pop of weird windows +, but you could install without the tests #CPAN::Shell->notest('install', $extramodule); print "Installation complete, calling use again...\n"; load $extramodule; } else { print "Module loaded\n"; } } } my $top = MainWindow->new(); print "Done\n";

        Edit: There are more than one ways to pack a camel. Your BEGIN block could just download&unzip a copy of your own lib directory and make sure it is in @INC. Or something along those lines.

        PerlMonks XP is useless? Not anymore: XPD - Do more with your PerlMonks XP
        Also check out my sisters artwork and my weekly webcomics
Re: How do I package up a Perl-TK app for macOS?
by Fletch (Bishop) on Nov 18, 2025 at 16:47 UTC

    Disclaimer haven't used it in aeons and it looks to be getting slightly long in the tooth but check out Platypus which can wrap up scripty things as applications. You might get something workable using that to wrap a PAR packaged version.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.