0

I have a python program that uses OpenCV to get frames from a video file for processing. I then create a standalone executable using py2exe (also tried pyinstaller and got same error). My computer and the target computer are both Windows 7, but the target computer does not have python installed. I use OpenCV to read the frame rate and individual images from a video file.

Problem: When I run the executable on the target computer the frame rate is returned as 0.0 and I cannot read frames.

If python is installed on the target machine then the executable runs as expected, otherwise it produces this error. So it seems that something is missing in the executable, but I get no errors when creating the executable to indicate what might be missing.

Others who have reported similar issues usually have not included the numpy dependency (and get an error indicating this), but I have included numpy. I have also tried including the entire PyQt4 module since this is listed as a dependency on the python xy site for OpenCV (I already have parts of PyQt4 for other parts of the code) and this does not solve the problem either.

Jay Eff
  • 11
  • 1
  • 5
  • 1
    py2exe is not perfect so will often miss some libraries or dll, pyd etc needed. Most likely you are missing opencv_highgui249.dll and opencv_ffmpeg249.dll etc. I would use py2exe with no single executable option enabled. And, start manually copying files that might be needed for your app. After identifying them, modify setup.py for py2exe to include them automatically. – otterb Apr 25 '15 at 10:16
  • Can you show your setup.py? The target machine should not have anything Python related installed, py2exe will include what is needed, also sometimes it needs a bit of help. – Werner Apr 28 '15 at 15:14
  • @otterb. I compared the dll files in my executable to the opencv_*.dll files found in the Python27/DLL folder. My executable contained only 14 out of the 20 found there (I already had opencv_highgui249.dll). I tried adding the 6 that were missing and that fixed the bug. It also fixes the bug if I only add open_cvffmpeg249.dll, but I am not sure if not including the others will lead to a different bug that I haven't identified yet. Thanks for the reply. Perhaps someone who understands how "hooks" work can submit one to pyinstaller for this issue? – Jay Eff Apr 30 '15 at 01:28
  • It seems that often the problem with executables using openCV is that numpy isn't included automatically. Adding it manually may solve the problem. – Fabio Aug 15 '16 at 22:50

2 Answers2

0

I guess I will go ahead and post an answer for this, but solution was provided by @otterb in the comments to the question. I am pasting the text here:

"py2exe is not perfect so will often miss some libraries or dll, pyd etc needed. Most likely you are missing opencv_highgui249.dl‌​l and opencv_ffmpeg249.dll etc. I would use py2exe with no single executable option enabled. And, start manually copying files that might be needed for your app. After identifying them, modify setup.py for py2exe to include them automatically."

I will note however that I use pyinstaller rather than py2exe, since I get fewer problems while building. I still have to manually copy the opencv dll files though.On Windows 7 they are located here: "C:\Python27\DLLs" and they need to be copied into the distribution folder so that they are on the same path as the other dll files that go with the distribution.

Jay Eff
  • 11
  • 1
  • 5
0

Try using pyinstaller, download it using pip :

pip install pyinstaller

if you don't know how to install pip , try downloading python 2.7.9 or above, which has inbuilt pip, but don forget to add python path to environment varibles, this procedure is mentioned in this post:

How to run Pip commands from CMD

After installing pyinstaller, select the main file of your project and run this command

pyinstaller yourprogram.py

it will create folder with application file naming your file name, and finally make sure that numpy and opencv are in lib->site-packages folder of your python27 in your C Folder while running that command

Hope it Helps!

David
  • 1,147
  • 4
  • 17
  • 29