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 !

4 Answers 4

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

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

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.

2 Comments

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.
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. :)
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.