Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 752
fdmillion Avatar asked Oct 05 '22 04:10

fdmillion


1 Answers

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.

like image 102
Ronald Oussoren Avatar answered Oct 13 '22 12:10

Ronald Oussoren