Search code examples
pythonpython-3.9py2app

py2app access non-python files


Currently I'm working on a python project (standalone application) which will use some non-python code (js/html). This code is already present in the directory and should therefore be included within the py2app application. I tried out different things to keep these files around so I can access them at runtime in the standalone application.

For the setup.py I use the following configuration

from setuptools import setup

APP = ['main.py']
DATA_FILES = []
OPTIONS = {}

setup(
    app=APP,
    data_files=DATA_FILES,
    include_package_data=True,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)

with include_package_data=True all files in the directory will be copied to the standalone application.

├── main.py
├── setup.py
└── writer
    ├── __init__.py
    ├── data
    │   ├── extra_data
    │   │   ├── content.txt
    │   │   └── nested_folder
    │   │       └── content.txt
    │   └── extra_data.zip
    └── fileManager.py

In the end I want to access the files in data/extra_data. As it turns out I cant access the files, since the are bundled in a python39.zip.

Is there any way to access these files within the package? Or is the only way to include an archive via DATA_FILES and un-zip it at runtime to access the files?


Solution

  • https://py2app.readthedocs.io/en/latest/options.html#option-reference Lists py2app specific configuration options.

    In your case using the “resources” option will help, that will copy files in the application Resources folder.