cx_Freeze - opencv compatibility

1.7k views Asked by At

I get a numpy.core.multiarray failed to import error whenever I try to build an exe file using cx_Freeze.

My system uses the following versions:

python 3.6.0

opencv 3.3.0

numpy 1.13.1

cx_Freeze 5.0

The code is:

import cv2
i=333
print(i)

It runs fine (i.e. builds a good exe file) only if I remove the import cv2 line.

Is there any incompatibility between the four modules I listed?

2

There are 2 answers

0
NP1 On

I managed to make this work only after I uninstalled cx_Freeze and installed Pyinstaller instead. It works like a charm.

0
jpeg On

If this can help you, I managed to make a working example under Linux using SimpleCV with the following configuration:

python 2.7.12
SimpleCV 1.3
numpy 1.11.0
cx_Freeze 5.1.1

The example code cv2_example.py is:

import encodings
import cv2
print cv2.__version__
i = 333
print i

The setup script setup.py is:

from cx_Freeze import setup, Executable

build_exe_options = {'packages': ['numpy']}

exe = Executable(script='cv2_example.py', base=None)

setup(name='cv2_example',
      version='1.0',
      executables=[exe],
      options={'build_exe': build_exe_options})

I guess this example could work also for your configuration with python 3.6.0 and numpy 1.11.0 provided you upgrade cx_Freeze to version 5.1.1.