sciter-sdk/pysciter

How to load files from pyinstaller's temp directory?

GirkovArpa opened this issue · 3 comments

Graphics.Image.load('image.png')

This tries to load the file image.png from the same folder as the executable. But, image.png is actually in a temp folder, because I've packaged everything into a single executable with pyinstaller, and when running it extracts everything to a temp folder.

So, how to tell Sciter to load image.png from the temp folder, and not the current executable's folder?

In other words, the same folder as index.html.

Also take note about Host.on_load_data, where you can intercept resources load requests and override with your own path:

Originally posted by @pravic in #11 (comment)

How would one go about this? I tried this:

def on_load_data(self, nm):
    nm.uri = sys._MEIPASS + '/' + nm.uri
    pass

But got this error:

Exception ignored on calling ctypes callback function: <bound method Host.handle_notification of <main.Frame object at 0x000002D5325D4430>>

TypeError: unicode string or integer address expected instead of bytes instance

I got around this issue by editing main.html on every run via python in order to insert the necessary path information. But others may still need a less hackish solution.

unicode string or integer address expected instead of bytes instance

What's the type of sys._MEIPASS + '/' + nm.uri?