2

I am building a small app that will be loaded on to a user's machine and it will need to look in the same directory as the bundle for specific mp3 files. These mp3 files will not be bundled with the py file, so I don't need the sys._MEIPASS path, but just the system path to the bundle itself.

Or, if I'm thinking about this in the wrong way, please advise. I'm not familiar with building apps in this way. We need a small app to modify specific mp3 id3 tags for users. The mp3s will be on their local machine or a usb drive. My idea is to just drop the script where the mp3s are and run it.

By the way, this is what I have tried...

    if getattr(sys, 'frozen', False):
        basedir = sys._MEIPASS
    else:
        basedir = os.path.dirname(os.path.abspath(__file__))

    mp3path = basedir + "/test.mp3"

When I test before building, it gives me the correct path:

    /Users/name/path/to/file/test.mp3

When I run the bundle, the mp3 path is:

    /var/folders/d8/67z60y2x7c73kk_m0w50w2pr0000gp/T/_MEI9qySOb/test.mp3

When I just use the dirname from __file__, the path is my user folder

    /Users/name/test.mp3
Deez
  • 43
  • 1
  • 5
  • This answer your question about the relative paths: [Relative paths in Python](http://stackoverflow.com/questions/918154/relative-paths-in-python), but not about bundling with PyInstaller. – iled Dec 15 '15 at 01:26
  • Thank you, but those don't work when running as an app. – Deez Dec 15 '15 at 01:31
  • Ok, sorry, I am not familiar with PyInstaller. However, please note that this approach is also referred in this [answer](http://stackoverflow.com/a/7887341/3079302). Are you sure that `your_script.__file__` will not return anything useful? – iled Dec 15 '15 at 01:36
  • 1
    Yes, that's the answer I've found too, but unfortunately it hasn't helped. Thanks though! – Deez Dec 15 '15 at 01:46
  • Was this ever solved after almost 4 years? – Mefitico Oct 02 '19 at 18:09
  • 1
    @Mefitico, no, I never got it working how I wanted. – Deez Oct 03 '19 at 19:23

0 Answers0