How to directly access a resource in Py2app (or Py2exe)?

This is mainly for Py2app, but I plan to also connect to Windows, so Py2exe is also applicable.

For Mac: How can I access the Resources folder of my application package from Python code? The ideal way for me would be to get the path to this folder into a variable that my classes add to any file that they need to access. Given the portability of OSX application packages, this Resources folder can be moved around, so it is clearly not acceptable to assume that it will always be located in /Applications/MyApp.app/Contents/Resources.

For development, I can set this variable to something like “./Resources-test”, but for the final distribution I would need to find the “Resources” folder to access the files in it as file objects.

On Windows: if I use py2exe, what is the correct way to get the path to where the application is from? (Think portable app - the application can be launched from program files or a directory on someone’s flash drive or in the temp directory!). On Windows, it would be convenient to just find out where the .exe file is, and just have the resources folder there. (I plan to use cross-platform applications using wxwidgets.)

thanks

+4
source share
1 answer

By default, the Resource folder is the current working directory for applications running py2app.

In addition, the environment variable "RESOURCEPATH" is set to the absolute path to the resource folder.

+2
source

Source: https://habr.com/ru/post/1479686/


All Articles