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).