App not working on Mac

Hello!
Created an app in python to work on Mac, the app works perfectly through terminal but shows error on Launcher. Am new to the mac environment. Please help me resolve this without breaking anything on Mac Ventura 13.5.

I created a python app for Mac(OS version- Ventura 13.5). Version of python used for development - 3.11.
The app was created using Py2app on Mac using the following command.

setup.py code given below

-------setup.py----------

from setuptools import setup

APP = [‘Process.py’]
DATA_FILES = 
OPTIONS = {

}

setup(
app = APP,
data_files = DATA_FILES,
options={‘py2app’:OPTIONS},
setup_requires=[‘py2app’],
)

-------End of setup.py----------

The app is created to read a text file that outputs another text file. Code is attached.

The app created in the dist folder was moved to the client mac. When the app is double clicked, the launcher shows this error(added below here)
When the app is executed using the command at the terminal, it runs without any issues providing the necessary output.
The user needs the double click to work without the need to use the terminal command every time.

-----Code from Process.py--------

import os
import hl7
from datetime import datetime


TestString = "301(23)12343"

Path = os.path.abspath(os.path.join(os.getcwd(), "../../.."))

Logfilename = "TestLog.txt"
LogOutput = os.path.join(Path, Logfilename)


def writelogfile(datatext):
    with open(LogOutput, "a",encoding='utf8') as ErrorLogfile:
        ErrorLogfile.write(str(datatext) + '\n')    
        ErrorLogfile.close()
writelogfile(Path)

print(Path)

-----End of Code from Process.py--------

LaunchError

Thanks
Kripa

@ronaldoussoren

1 Like

Wrap ALL your code in a try block and write any exception that happen with traceback to a log file.
I tend to hard wire to a file in my home folder.
Do not trust that the cwd or environment is what you have in a terminal session.
I write cwd and all the env to the log file when i debug this type of situation as well.

My guess is that you are not in the cwd that you assume.

1 Like

Are you sure that setup.py is correct? I ask because what you posted has nothing after the DATA_FILES = and also that code uses smart quotes (the and ) instead of plain quotes (').

1 Like

Try launching the app by running the binary directly from Terminal (e.g. path/to/Process.app/Contents/MacOS/Process). That will often give clues about what’s going on.

If I’d have to guess something in h17 is confusing py2app, possibly add a “packages” option (see py2app Setuptools Configuration — py2app 2.0a0 documentation)

1 Like