简体   繁体   中英

OpenCV with standalone python executable (py2exe/pyinstaller)

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.

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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM