1

Hello I have a program that I wrote. It reads en excel file and inserts it into sqlite. It is like a CLI. It works very well on terminal. But after I compile it with pyinstaller It took 1m20s to read and write 16 rows of excel file. On VSCode (or without compiling it) it takes few seconds.

Is it about pyinstaller? I tried with and without --onefile.

Since it has other functions It is relatively large to post here.

Deccoyi
  • 29
  • 1
  • 7
  • 1
    Executables compiled with `--onefile` are slower (see the [doc](https://pyinstaller.org/en/stable/operating-mode.html#bundling-to-one-file)). I guess loading dependencies takes a while on startup. – Tranbi Jul 18 '23 at 06:05
  • Have you create a virtual environment for the specific script ? If not you may have put to your `one file` many unnecessary packages! what's the size of the executable ? – Kostas Nitaf Jul 18 '23 at 13:47
  • I've seen and read about `--onefile`starting slower. But my problem is it works slower. Starting delay is not my concern at the moment :) The program reads an excel file with 16 rows and 1 word on each row. Checks if that word exists in sqlite database if not performs an insert operation. This takes almost 1.5 minutes with pyinstaller executible. If I run the script on terminal it takes couple seconds. ps: yes I have an venv :) – Deccoyi Jul 19 '23 at 21:16

2 Answers2

4

The problem lies probably in a misconception of what using PyInstaller does (and does not) achieve:

PyInstaller does not compile your code into anything like optimized machine code that is supposed to run faster than regular Python code (which is what the term "compile" might imply)*. Instead, its purpose is to provide portability for your code: PyInstaller wraps up your code together with all the dependencies that are needed to run it into a single folder (default) or file (using PyInstaller's --onefile argument). In a sense, it provides a portable minimum Python environment to run your code – see What PyInstaller Does and How It Does It.

Especially with --onefile, this means that the bundled code has to be extracted first before it can be run. This, in turn, means that a small snippet of code will be much slower when run from a PyInstaller bundle than when run directly in your Python terminal or IDE, precisely due to this extraction overhead.

*) Yes, it works with bytecode versions of your code (i.e. *.pyc files), but these are also produced by your Python terminal or IDE and thus should not make a difference in running time (you can read more on the role of bytecode files in this discussion).

simon
  • 1,503
  • 8
  • 16
-1

The issue is in pyinstaller. if want run the script directly write script in bash that runs your