How to directly access a resource in a Py2app (or Py2exe) program?
Asked Answered
I

1

6

This is mostly for Py2app, but I plan to also port to Windows so Py2exe is also applicable.

For Mac: How can I access the Resources folder of my app bundle from Python code? The ideal way for me would be to get the path to this folder into a variable that my classes prepend to any file they need to access. Given the portable nature of OSX app bundles this Resources folder can move, so it's obviously not acceptable to assume it'll always be at /Applications/MyApp.app/Contents/Resources.

For development I can preset this variable to something like "./Resources-test" but for the final distribution I would need to be able to locate the Resources folder to access files therein as file objects.

For Windows: If I use py2exe, what's the correct way to get the path to where the application is running from? (Think portable app - the app might be running from Program files, or a directory on someone's flash drive, or in a temp directory!) On Windows it'd be suitable to simply know where the .exe file is and just have a Resources folder there. (I plan to make cross-platform apps using wxwidgets.)

Thanks

Incestuous answered 8/5, 2013 at 7:5 Comment(0)
C
5

By default the 'Resource' folder is current working directory for applications started by py2app.

Futhermore the environment variable "RESOURCEPATH" is set to the absolute path of the resource folder.

Conjecture answered 13/6, 2013 at 10:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.