I have used PyInstaller to create a standalone/windowed .app file using the command pyinstaller --noconfirm --windowed main.spec
using the default .spec file.
I then use pkgbuild
and productbuild
to create installers. However, whenever I run my program after using the installer, I am utterly unable to create files. For example, with the default logging module, when my program hits the line fileHandler = logging.FileHandler(resource_path("log.log"))
the program crashes with PermissionError [errorno 13] permission denied
. Note that the resource_path function is:
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
I have seen some tutorials and threads saying that the error is with the location of the file. Shouldn't I be able to at least create the file from within the app's .app/Contents/MacOS directory?
Thanks for any help you can provide.
So the problem was, the .pkg installs as root, and gives only the owner (root) read/write/execute permissions; everyone else only gets read/execute.
A workaround was to sudo chmod -R 777 the application as a postinstall script. To make this easier for anyone else, I setup a boilerplate application that will handle the entire process using pyinstaller and bash scripts: https://github.com/The-Nicholas-R-Barrow-Company-LLC/python3-pyinstaller-base-app-codesigning
Edit: made a library with pip: https://github.com/The-Nicholas-R-Barrow-Company-LLC/PyMacApp