6

I have designed a small application in Python under Windows, that uses opencv. I amm trying to create an executable so that anyone can install and use it, without having to install python/opencv/numpy . . .

I tried to use py2exe for this. It actually creates a .exe file, even though I have a warning during the build :

*** copy dlls ***
copying C:\Windows\system32\MSVFW32.dll -> 
...
The following modules appear to be missing
['cv2.cv']

When I try to run the .exe file using the command line, I see the message :

ImportError: numpy.core.multiarray failed to import

My setup.py file is pretty simple :

# creating executable here
from distutils.core import setup
import py2exe, sys, os

sys.argv.append('py2exe')

setup(
    options = {'py2exe': {'bundle_files': 1}},
    console=['facemovie.py'],
    zipfile = None,
)

Any idea how I can solve this? This is the very first time I want to deploy, and I may be missing something.

Thanks !

jlengrand
  • 12,152
  • 14
  • 57
  • 87

4 Answers4

3

According to this post, py2exe is not detecting that this module is needed inside the ZIP archive. I don't know the right syntax so you'll have to check the docs, but you could try:

python setup.py py2exe -p cv2

Or you could try to tweak setup.py to the following:

options = {'py2exe': {'bundle_files': 1, 'packages': 'cv2' } },

And if you are willing to try something completely different, take a look at bbfreeze:

create standalone executables from python scripts

Community
  • 1
  • 1
karlphillip
  • 92,053
  • 36
  • 243
  • 426
3

I would also recommend using PyInstaller. I used it for a project of mine that referenced both pycrypto and twisted and it worked like a charm.

Richard Nienaber
  • 10,324
  • 6
  • 55
  • 66
2

Thanks karlphilip, you put me on the tracks.

I wanted to avoid the "change my software utility" solution, so I stuck with py2exe.

Actually, opencv was correctly found, but the library itself has a numpy dependancy, which was not detected.

So my working solution is finally : options = {'py2exe': {'bundle_files': 1, 'includes': 'numpy' } },

The final executable is pretty big, but running smoothly.

I did not try on another computer, that does not have the software installed though, so there might be surprises to come.

Thank you both for your help.

jlengrand
  • 12,152
  • 14
  • 57
  • 87
  • 1
    You asked this question 4 years ago. I'm curious, did you try on another computer without open cv installed? I'm curious to know if it works in that case. – Fabio Aug 14 '16 at 23:08
  • It's been a long time so I won't remember for sure but I am pretty confident I did try this on PCs without OpenCV on them. :) – jlengrand Feb 16 '17 at 08:36
0

I came across the same problem. I resolved it by moving the image file to the folder where the executable is created.This worked for both py2exe and pyinstaller.

Nikki101
  • 69
  • 2
  • 8