Search code examples
pythonopencvcompiler-errorscx-freeze

cx_Freeze is not detecting cv2


I'm trying to compile a program with cx_Freeze which requires OpenCV (cv2). I use the standard setup.py format for building my EXE.

import cx_Freeze

executables = [cx_Freeze.Executable("test.py")]

cx_Freeze.setup(
    name="help",
    options={"build_exe": {"packages": ['cv2']}},
    executables=executables

)

cx_Freeze claims that there is no module named cv2.

Here's what I've tried:

  • 1.) Add full path to cv2 file.
  • 2.) Include cv2 under the includes: [] option.

Option number 2.) successfully compiles the program but claims that the cv2 module is not found. Option 1.) fails to compile because cx_Freeze can't find cv2.


Solution

  • cx_Freeze and OpenCV have some linking/compatibility issues, as reported here.

    Try switching to PyInstaller, or setup a conda environement at your "target" Windows machine.