Is there a way (free) to make a program in Python code into an executable for a Mac? (I am on a PC and it says no)

I am amazed at how hard it is to turn a program into an executable even for a PC. You have to type in some arcane script into a command window (and be sure you are in the right directory and all that) to poop out a program…which was the whole point of writing a program. Why this is not a button push in the GUI I do not understand.

But wait! It gets worse! Want to make the program run on a Mac? Well you can just f-off. You can’t. You have to compile it on a Mac if you want to run it on a Mac. At least, that is what all my Googling is telling me.

So, save me SDMB with your infinite wisdom! Is there a somewhat easy way to turn my Python program code into an executable that will run on a Mac???

(FWIW I have made it into an EXE that runs on a PC just fine.)

ETA: I am on Windows 10 using Visual Studio.

Well, first of all, Python is not usually compiled. It’s executes in its source code form as a script, by a Python interpreter installed in the computer. As such, the interpreter program has to be specific to operating system and hardware, but the script itself should be more universal.

That’s also why compiling Python to a standalone executable is inconvenient: it’s absolutely the minority use case. Virtually no one needs to do that, so virtually no one has gone to any effort to make it drool-proof.

What you’re talking about is orders of magnitude harder: cross-compilation from one system to a radically different target system, in both OS and processor. Again, it just never needs to be done, so it’s not convenient (assuming it’s possible at all. It might be, looking at Google returns, but absolutely no easier than the process you’re already complaining about for Windows executables.)

Also, I don’t think MacOS will run an executable that hasn’t been digitally signed by the developer, so you’ll have to fake that step as well.

Yeah, you can’t really just distribute random binaries anymore without jumping through hoops with code signing. It would typically be better to just distribute the .py file itself with instructions on how to run it (e.g. brew install python on a Mac).

Do you remember this previous thread, though? Turning a Python app into a web app for easier distribution?

TLDR you can just put your Python code in https://pyscript.net/ and then anybody with a web browser can run it, no downloads or even Python interpreter needed.

Wow…I totally forgot about that one (I usually remember old threads but that one went completely out of my clearly addled mind).

Thanks!

Heh, same! I went through that whole thought process in my head of “Well, you could package it, but code signing… you could get around that, but… wait, what if you could just package it for web distribution instead… huh… wait, that sounds vaguely familiar… I wonder if we’ve discussed this before…”

Lo and behold, it was you and me having that same discussion not even a year ago! Shall we do it again next year? :joy:

How are you creating the .exe? PyInstaller? With that one you indeed can only do this on the same platform. You’re right that it’s not really supported on a language like Python. I wonder if you can set up a VM Mac?

Yes…which is also weirdly unwieldy to make work (but it does work).

Why is this not advertised? I am not a programmer so I Googled most popular programming languages and Python was in the lead by a mile. But nothing said you can’t actually make a program out of it cuz that is not what it is meant for.

Why is this shit so obscure? You have to be in the special club to know?

This info should be on billboards with lots of lights!

It’s not compiled because it’s usually an interpreted language. Like many languages before it (shell, perl, the original implementations of BASIC…)

As to why that’s not well known, I dunno. Most people wouldn’t know a compiler if it dumped core on them, so the distinction is outside of 90% of the human race’s experience.

Just a guess, but it may involve portability. Identical — or minimally tweaked — Python code should run the same on any platform if the correct interpreter is being used.

(Disclaimer: I only started playing around with Python after I retired, so I’m anything but an expert. But I did write a database inquiry program that runs equally well on both Windows and Linux, the only qualifier being that I had to identify the operating system and set a separation character accordingly.)

Because it doesn’t really matter for the use cases where Python is typically popular, like data science or GIS or education or home automation or general hobbyist programming.

Python IS a popular programming language: Technology | 2025 Stack Overflow Developer Survey

But programming languages don’t have to be compiled.

Compiling programs isn’t as important as it used to be in the 90s and prior, when computers were way slower and interpreted programs were meaningfully slower and the Web was a much less mature platform. These days, many popular languages (Python, Javascript/Typescript, PHP, Ruby, Lua, etc.) are usually interpreted at runtime, and many other languages/systems do some sort of hybrid compilation.

Compilation isn’t strictly “better”, because it can make distribution more difficult (as in Python and code signing), security more problematic (direct memory access can lead to classes of security issues), and the developer experience worse (you have to wait minutes or hours for a compile, instead of the mere seconds it usually takes in Python or Javascript), etc.

Compilation can have performance benefits (primarily), but computers and phones are so blazingly fast the CPU is almost never the constraint anymore. For things like AI and data crunching, the real work is offloaded to the GPU anyway and the Python part is just glue code that isn’t doing the actual number crunching.

Outside a few niche areas like gaming or real time audio and operating systems, compilation just doesn’t matter all that much anymore.

What you’re talking about is more an issue with packaging and operating system rules on code distribution. That’s not a matter of compilation per se, but of each operating system’s balance of ease of use, security, and performance. That can change over time too, like even in Windows’s own case when the traditional Win32 EXEs were eventually replaced by somewhat interpreted/hybrid systems like dotNET and distributed via Clickonce (and then changed even more later on). iPhones, Macs, and Androids have their own setups that also changed over time.

Part of the reason I suggested PyScript is because the Web has become kind of a de facto evergreen distribution platform where you can write your code any way you like and some “runtime” (in this case a Python interpreter running in WebAssembly) seamlessly executes the code for you, all without your user knowing or caring and using the common UI language of HTML.

If instead you compiled it, you’d have to deal with differences in UI across platforms, different human interface guidelines, different permissions systems (like whether the app is allowed to access files in other folders), different terminals/shells and hotkeys and varying levels of ANSI color support and like breaks and path formats and user home directories and all that nonsense, on top of actual operating system and kernel and hardware differences.

The web abstracts all of that away so you can focus on just the business logic, the part of the code you actually care about. Let the interpreters and runtimes and browsers take care of the rest for you. In fact the desktop software world has moved so far in this direction that many apps that look like EXEs or Mac packages are actually just websites packaged up in an executable outer layer to abide by OS distribution rules, but beneath the hood they’re just HTML and Javascript.

That compilation is less important now is an orthogonal issue… mostly you’re just running into Apple’s security requirements and their unwillingness to play nice with the PC world and the VM (virtual machine) world, so it’s not so easy to cross-compile for macOS or iOS unless you have access to one, or at least access to a VM running on real Apple hardware. It’s just a licensing and greed thing on Apple’s part, not Python’s fault.

This is the SDMB at its best.

Thanks so much for all that detail. I really appreciate it.

What sort of program are you writing? Does it do some calculations and print them out to the screen? Or is a GUI with windows and mouse actions? If it’s the former, that would be relatively easy to get running on the mac. But if your program has GUI components, then it gets more complicated to have it run on both Windows and Mac. The way that Windows and Mac does graphics is different, so a program that is designed for Windows GUI might not work with Mac GUI.

Another, less technical way to think about this: I don’t think you made a mistake in choosing to learn Python first (at all!). It IS in fact one of the most popular programming languages (and getting more popular every year!). The only other contender with similarly broad popularity & compatibility would be Javascript.

The distribution difficulty you’re running into is because Apple is plainly a PITA for developers. Even if you used their own Xcode and Swift, you’d STILL run into distribution and code signing headaches. Many cross-platform open source packages are harder to run on macOS because of this, and some developers don’t even bother when they don’t want to pay the $99/year (or however much it is now) to get an Apple developer account. I’ve been a programmer for decades and I use two Macs at work and in my personal life, and I still don’t bother with this or trying to deploy binaries to other Macs.

And even then, you’d run into the opposite problem: Difficulty trying to deploy it to Android or iOS or Windows or Linux.

The Web is the closest thing we have to a universal software platform, and Python is second only to Javascript in terms of being a web-friendly language, on top of also being wildly popular in other fields (especially AI and the sciences). For your first programming language, it really isn’t a bad choice at all!

But for the particular case of “I want to write a program that all my coworkers can easily run, regardless of their computer system”, well, that isn’t a question of programming language but of distribution system, and that’s where the Web and WASM (PyScript) come in. Luckily for you, generalist Python code can easily be made to run on the web, which is not necessarily the case with something like C++ or Swift.

I put out a daily newsletter.

The newsletter is made in a GoogleDoc. We use certain code to make things happen (e.g. brackets link to our webpage on that topic).

The program formats all that for an email we send daily to our subscribers.

As an example I would write [[filmore]] and the program would turn it into a link like this: filmore

There is a lot more but that is the basic idea.

For what it’s worth, you can probably ask an AI for help turning that Python code into Google Docs Apps Script code (basically Javascript) so that it can run directly in Google Docs: Extending Google Docs  |  Apps Script  |  Google for Developers

(This is basically Google Docs’s answer to Microsoft Word’s VBScript macros)

I can make you an example if that would be helpful?

But again, for something like this (string manipulation), the choice of programming language is way less impactful than the choice of distribution system. An Apps Script right inside the GDoc is easier to run than a separate webpage which is easier to run than a distributed Python script which is easier to run than an unsigned binary, etc.


If your mailing lists get complicated enough, eventually you might consider moving to a proper templating system, whether in Python or another language (like every major mailing list software has their own, basically modernized and more powerful versions of “mail merge”). That’s a bridge you can cross when you get there, if you get there…

It sounds like your program is just regular Python without any GUI stuff to worry about. In that case, it should be pretty simple. You would just need access to a Mac. You could run a tool like PyInstaller on the Mac to create a Mac executable. You’d need to copy over the .py files from Windows to the Mac and then run the .py-to-executable tool. If that sounds like Greek to you, I’m sure we could talk you through it.

The code signing stuff is a non-trivial part of this, though. Unless @Whack-a-Mole is willing to pay for an Apple code signing certificate, none of his coworkers would be able to run that executable without jumping through hoops. And access to a Mac (even in a VM) typically isn’t free, either.

Edit: And also, updates will be a forever pain in the ass unless he puts it on the app store or an internal distribution system. He’ll have to manually send coworkers updated versions every so often (and they’ll have to jump through the hoops every time!). Or he’ll have to keep renewing his developer certificate every year to be able to publish new versions that they can run (and still have to send it to them every time).

(Note: I don’t recommend this. It’s highly complex and fragile.)

In the spirit of trying to answer the OP, though… if you’re willing to make your Python code public and put it on Github, you may be able to use their Github Actions on a macOS runner within the free tier limits to build it into an executable with PyInstaller in the cloud.

This would still have the code signing issue, unfortunately, and you would also have to cross-compile not just for Macs but separately for the older Intel Macs and the newer Apple Silicon Macs (unless you can figure out how to get Apple “Universal2” builds working on Github Actions).

But it would technically be a free way to build a Python executable for Macs, without having access to one.

The PyInstaller project in fact itself uses this approach to test its macOS builds: pyinstaller/.github/workflows/ci.yml at develop · pyinstaller/pyinstaller · GitHub. This is a good real-world example (just skimming through the comments) of how complex it can actually be to build for multiple platforms.

Or see an explanation here: Build a multi OS Python app in the cloud: PyInstaller on GitHub Actions - Data-Dive


But really not recommended. It would be a LOT simpler (for you) to just put it in PyScript and share a URL that way. Or it would be simpler (for your users) if you took the time to port it to Google Docs AppScript instead.

It sure would and I really (really really) appreciate the offer but that is too much for me to ask.

That said…I may IM you for some help here and there if you are ok with it.

While none of this has happened (yet) if you ever get to Chicago let me know and I will take you out for a fantastic meal…my treat.

Sure, post or DM me your current Python code (or the relevant snippet) and I’ll do my best.

And would definitely take you up on that meal next time I’m there! I used to live in Chicago and never had a bad meal there :slight_smile: