Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create executable for application using opencv?

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 !

like image 807
jlengrand Avatar asked Apr 19 '12 20:04

jlengrand


People also ask

Does PyInstaller support OpenCV?

opencv is supported as of https://github.com/pyinstaller/pyinstaller/pull/36. You'll need to use the current development version, of course.

Can you convert Python script to Exe?

In order to more easily run Python scripts on Windows machines, you can convert Python to .exe files using either cx_freeze or PyInstaller.

What is an executable in Python?

The one executable file contains an embedded archive of all the Python modules used by your script, as well as compressed copies of any non-Python support files (e.g. . so files). The bootloader uncompresses the support files and writes copies into the the temporary folder. This can take a little time.


2 Answers

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.

like image 200
Richard Nienaber Avatar answered Sep 20 '22 11:09

Richard Nienaber


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

like image 38
karlphillip Avatar answered Sep 22 '22 11:09

karlphillip