Colorful Wires


Create an executable file containing icecream with pyinstaller

When you try to convert a Python script that loads icecream into an executable with pyinstaller, it doesn't work.

The error message is as follows:

Traceback (most recent call last):
  File "", line 1, in <module>
    from icecream import ic
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "PyInstaller\loader\", line 546, in exec_module
  File "icecream\", line 20, in <module>
FileNotFoundError: [Errno 2] No such file or directory: '***********\\icecream\\'

This error is caused by icecream running icecream/ with the exec() function, so needs to be included.

The solution is as follows:

Edit the .spec file for pyinstaller.

Add the following to the top:

import os
import icecream
icecream_path = os.path.abspath(icecream.__path__[0])

Next, add Tree() as an argument to the COLLECT() function like this:

coll = COLLECT(exe,
               Tree(icecream_path, prefix="icecream"),