3

Environment: mac os x 10.7.5, xcode 4.2.1, python 2.7.5, opencv 2.4.7, py2app 0.7.3

I am trying to package a simple opencv based python script using py2app but the built app crashes with an error that says ImportError: numpy.core.multiarray failed to import

here is the python script called demoApp.py

import cv2
capture = cv2.VideoCapture(0)
winName = 'eyeDetection'
cv2.namedWindow(winName)

# Press esc key to exit
keyPressed = -1
while(keyPressed != 27): # ord('esc') is 27
    unused_retval, img0 = capture.read()
    img1 = cv2.cvtColor(img0, cv2.COLOR_BGR2GRAY)

    cv2.imshow(winName, img1) 
    keyPressed = cv2.waitKey(1)
cv2.destroyAllWindows()

demoApp.py runs as expected when launched from eclipse+pydev IDE.

I create the setup.py file:

py2applet --make-setup demoApp.py

which has the following content:

"""
This is a setup.py script generated by py2applet

Usage:
    python setup.py py2app
"""

from setuptools import setup

APP = ['demoApp.py']
DATA_FILES = []
OPTIONS = {'argv_emulation': True}

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)

I then build the app:

python setup.py py2app

Running the app causes it to crash with the above mentioned ImportError.

I deleted the build and dist folders and tried building the app in "alias" mode:

python setup.py py2app -A

Then when I run the app it runs as expected. So I don't understand why the standalone app won't work when built for distribution.

Please help me figure out how to deal with this issue. Also, the demoApp.app is 50Mb, how can I reduce its size?

samkhan13
  • 3,315
  • 2
  • 33
  • 54

1 Answers1

2

though I haven't found a proper solution and this problem might be due to 64bit python27 and 32bit numpy computability issues a quick work around was to import numpy in the demoApp.py script before importing cv2.

and after using PyInstaller instead of py2app the demoApp.app file is now 6Mb instead of 50Mb :D

though the app generated via PyInstaller gave the same problem without the above workaround.

samkhan13
  • 3,315
  • 2
  • 33
  • 54
  • Though I haven't seen this precise issue, I can confirm enough issues similar with 64-bit python that I don't even use 64-bit python anymore. I just don't think the ecosystem is ready yet, even in 2016 – Jonathan Feb 18 '16 at 02:08