1
  • Operating System: macOS Catalina 10.15.7
  • Python Version: 3.10.1 (latest)

I would like to convert a .py file into a standalone app bundle for macOS and an executable for Windows. Said .py runs within my system terminal, and when I create my executable/app bundle, I want the terminal to run in the background.

Currently, I run my .py file in a virtual environment with the required modules, operating on Python 3.10.1. I do so by activating the environment and running:

python /main.py

in my file directory within my terminal. This runs my script just fine within the terminal, but this is not the final product I want and I'm having trouble converting it into an app bundle.

I have tried using py2app to achieve this, first running:

py2applet --make-setup main.py

in my program directory in order to make the setup file, then by running:

python setup.py py2app -A

to make the Python alias. The alias runs fine when I put click on the unix executable within Contents>MacOS>myprogram.py, but it doesn't run at all when I delete my dist and build folders and remake them without the alias. It says "Launch Error: See the py2app wesbite for debugging launch issues". I visited the website but am still unsure what to do about this.

So to summarize, I have two goals:

  1. Create sucessful standalone app bundles and executables for my script without recieving a launch error.
  2. Run said executable or app bundle in the background where the terminal is not visible if I manage to complete goal one sucessfully.
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
dingodean
  • 11
  • 2
  • @Tomerikoo I don't think that `macOS` can run an `exe` file (at least not [easily](https://cleanmymac.com/blog/run-exe-files-mac)) (although they asked for Windows too) – Matiiss Dec 29 '21 at 22:35
  • 1
    @Matiiss good point. Maybe [this](https://stackoverflow.com/q/36564320/6045800) could be relevant – Tomerikoo Dec 29 '21 at 22:36

1 Answers1

1

You can create standalone windows executables with pyinstaller. You can install it with pip.

pip install pyinstaller

After installation, navigate to the directory that your .py file is in. Then simply execute this command in Terminal:

pyinstaller yourfile.py
Dharman
  • 30,962
  • 25
  • 85
  • 135
KylianJay
  • 55
  • 1
  • 8