need help to compile python with pyinstaller
Asked Answered
S

2

2

I want to distribute my python code on machines running windows 7+. It consists of a couple of .py files with the main in cprofiles_lmfit.py, together with a file cprofiles.ui to describe the GUI and a .pdf for the doc.

I had a hard time (see build a .exe for Windows from a python 3 script importing theano with pyinstaller for instance) but eventually made a suitable binary using pyinstaller with the command line:

pyinstaller --noupx --onefile --add-data="cprofiles.ui;." cprofiles_lmfit.py

beside a problem with the theano module described in the above link, the binary still have a few problems:

  • the .exe is 220MB big; I would like reducing the size.

  • when running the .exe a console opens and waits ~20 seconds before opening the GUI. Once the GUI is opened, closing the console kills the GUI... I would like avoiding this console and skip the ~20s.

  • the ui file must be distributed together with the exe (in the same directory); I had hoped this shouldn't be the case with the 'add-data' option. I would like including it.

  • the ‘platforms’ directory from the ‘Library/plugin’ directory of the python environment must also be distributed along with the exe. Otherwise there is an error message when running the exe ‘this application has failed to start because it could not find the qt platform plugin windows’ (but there is no error message from pyinstaller when building !). I would like getting rid of this 'platforms' game.

Do you know how to address one these points ?


update nov 28, 2017: no one ? please if you can contribute to one of these points, give me a clue.

Samaritan answered 18/10, 2017 at 20:48 Comment(0)
C
3

I think I have a better solution for you: Use nsis in conjunction with pyinstaller.

Here the answers in more detail:

  1. The file is that big because it contains the full python environment. I don't think there's much you can do about it, except creating a virtual environment that contains less files and using less packages in your code.
  2. Running the exe takes a long time because you have chosen the --onefile option. As a result it will unzip the exe, save it to a temporarary directory, and then run the script. When using --onefile it's actually not really an executable, but just a zip file that unzips and then starts itself. A better option might be:
  3. (and 4.). Instead of using the --onefile option, just package it normally with pyinstaller, and then create a script on top of it with nsis. That way the user can run the installer, which will have packaged all the files you put in the nsis script (including all the files created by pyinstaller) and also any additional files you would like. There will be a nice setup interface that will also create a shortcut to the .exe.
Consolidate answered 28/11, 2017 at 10:36 Comment(0)
C
1

A little too late but, incase someone stumbles here later on, you can use 'auto-py-to-exe' package to remove the hassle of using CMD. It provides a nice GUI with all the options of 'pyinstaller'.

It can be installed using 'pip install auto-py-to-exe' and Can be used with 'auto-py-to-exe' at terminal.

GitHub link : https://github.com/brentvollebregt/auto-py-to-exe

Consummate answered 3/12, 2019 at 14:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.