Compiling to exe including MIP in to one exe file

I have used hours … no days … to find out how to compile my Python program in to only one executable exe file (Windows, Python, coin-or MIP, PyInstaller).

I have made a Python program that uses file from this library: python-mip/mip at master · coin-or/python-mip · GitHub. The program works when running it from Python. I know how to use PyInstaller and by following the following guide I can generate a executable exe file, but the coin-or/MIP files are separate files that is not a part of the exe file: PyInstaller with mip "NameError: name 'cbclib' is not define" · Issue #198 · coin-or/python-mip · GitHub

My question is: How to compile my program in to only one exe file that can run on an other computer without any additional files included?

The github issue you linked to contains a post which at least one user reports as solving the problem for them: PyInstaller with mip "NameError: name 'cbclib' is not define" · Issue #198 · coin-or/python-mip · GitHub

Have you tried it? If it didn’t work for you, what problem did you encounter?

The compiling it self worked, but the final exe file still require that the MIP files are available when executing the exe file. By other words: the MIP files were not included in the exe file.

What error do you see, exactly?

This is the error I get now:

File “C:\Users\jp\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py”, line 1170, in add_script
contents = importlib.util.decode_source(contents)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “”, line 770, in decode_source
UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xf8 in position 292: invalid start byte

I solved the error by copying all files in to a subfolder to Python.

The compiling cmd command I use in this folder is “pyinstaller -D filename.py --additional-hooks-dir=./hooks/”

The compiling generates a “dist” folder with the exe file and beside that a folder called “_internal”. This “_internal” folder contain a lot of tiles from the MIP library.

If I execute the exe file from the folder generated, then it works.
If I move the exe file to an other folder, then it don’t work.

It seams like the exe file have to have access to the subfolder “_internal”. How do we solve this?

A few lines from the building process:
23956 WARNING: Hidden import “importlib_resources.trees” not found!

32861 INFO: Building EXE from EXE-00.toc completed successfully.
32876 INFO: checking COLLECT
32876 INFO: Building COLLECT because COLLECT-00.toc is non existent
32876 INFO: Building COLLECT COLLECT-00.toc
34215 INFO: Building COLLECT COLLECT-00.toc completed successfully.

There only one warning that I have listed. I don’t know what this waring means?

I have found a solution to this problem:

  1. Ensure that the files is in a subfolder to the Python installation
  2. Remember to include the PyInstaller feature “–onefile” like this: pyinstaller -D --onefile filename.py --additional-hooks-dir=./hooks/

Alexander Bessman - thank you for spending time on this. Your questions guided me to look more in to the details.

1 Like