0

I am trying to package together a sciter project that I have made. In sciter, it uses .htm and .css files. So I'd like to include this into my .exe and not have to include them separately. Here is how I the HTML file is used in the Python code:

    # create window
    frame = Frame()

    # load file
    frame.load_file("index.htm")

    # install additional handler
    ev2 = RootEventHandler(frame.get_root(), frame)

    frame.run_app()

And here is how I create my exe using PyLauncher: pyinstaller --add-binary "index.htm;index.css" launcher.py --onefile

NOTE: I am running this on Windows.

When I run my launcher, it says:

sciter.error.SciterError: Unable to load file file://C:/Users/user/launcher/dist/index.htm
[14684] Failed to execute script launcher

If I place the index.htm file and index.css file, it works fine however. So clearly, it is expecting those files to be included in the directory.

brilam
  • 53
  • 2
  • 11
  • Can you share the tree structure of your directory so that I can clearly see the relative path of index.htm and other non-python files. Then I can exactly tell you the change required in your spec file, so that you don't have to place any of these files to run your exe – Shubhendu.py Aug 01 '20 at 10:28
  • Hi. So how this looks right now: All my files are in the root folder of the project. So: Root folder of project: -> launcher.py -> updater.py -> requirements.txt -> index.css -> index.html -> icon.ico I'd like to include index.html/index.css/icon.ico in the exe. – brilam Aug 01 '20 at 16:45

3 Answers3

0

Data/Resource files cannot be incorporated within an executable simply because they aren't treated as code, and are instead required as data/media/resource within the main program's code. What you can do however, is revise your .spec file, to include the files in your directory automatically when you run pyinstaller along with the spec file. The datas field holds a list of files/resources that need to be included in the distribution directory.

datas=[
                 ('index.htm', '.'),
                 ('index.css', '.')
             ],

This tells pyinstaller to place files index.htm and index.css in the root folder of your executable.

Syed H
  • 270
  • 1
  • 3
  • 13
  • Hi, I attempted to do that, but it still requires the index.htm and index.css files to placed in the same folder as launcher.exe – brilam Jul 28 '20 at 03:12
  • The files placement within the executable's folder is must for the executable to work.Following my solution does exactly that. If it isn't doing so, check if your executable is located at `C:/Users/user/launcher/dist/`? If it doesn't work despite being situated there, try changing `frame.load_file("index.htm")` to `frame.load_file("./index.htm")` – Syed H Jul 28 '20 at 03:19
  • My question isn't asking for how to get the exe working with those files inside my folder. I want to embed these files into the exe. Is that possible? – brilam Jul 28 '20 at 03:35
  • Like I mentioned in my solution, resource files cannot be embedded into the exe – Syed H Jul 28 '20 at 03:40
0

You need to explicitly tell pyinstaller the non-python files to be included and embedded inside your exe. As per the pyinstaller documentation, you need to use --add-data <src;dest> ( which I think Syed H tried to answer)

Following command will embed these non-python to your bundled application

pyinstaller --add-data="index.htm;." --add-data="index.css;." --add-data="icon.ico;." --onefile launcher.py

NOTE: It is possible to embed data(non-python) into the exe. As I do it daily. If you still see the error, maybe you might want to include the content of .spec file in your question for a better insight.

0

there are multiple ways:

  1. Add individual files while packing
  2. put all files in a folder and add it while packing

and if you don't know how to do the above steps then simply use GUI tool

Use this small web app for it, really handy

Gaurav
  • 41
  • 6