简体   繁体   English

具有独立python可执行文件(py2exe / pyinstaller)的OpenCV

[英]OpenCV with standalone python executable (py2exe/pyinstaller)

I have a python program that uses OpenCV to get frames from a video file for processing. 我有一个使用OpenCV从视频文件获取帧进行处理的python程序。 I then create a standalone executable using py2exe (also tried pyinstaller and got same error). 然后,我使用py2exe创建一个独立的可执行文件(也尝试使用pyinstaller并出现相同的错误)。 My computer and the target computer are both Windows 7, but the target computer does not have python installed. 我的计算机和目标计算机都是Windows 7,但是目标计算机未安装python。 I use OpenCV to read the frame rate and individual images from a video file. 我使用OpenCV从视频文件中读取帧速率和单个图像。

Problem: When I run the executable on the target computer the frame rate is returned as 0.0 and I cannot read frames. 问题:当我在目标计算机上运行可执行文件时,帧速率返回为0.0,而我无法读取帧。

If python is installed on the target machine then the executable runs as expected, otherwise it produces this error. 如果在目标计算机上安装了python,则可执行文件将按预期运行,否则会产生此错误。 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. 报告了类似问题的其他人通常不包括numpy依赖项(并得到指示错误的信息),但我包括了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. 我还尝试包括整个PyQt4模块,因为它被列为OpenCV的python xy站点上的依赖项(我已经拥有PyQt4的其他代码部分),而且这也不能解决问题。

I guess I will go ahead and post an answer for this, but solution was provided by @otterb in the comments to the question. 我想我会继续为此发布答案,但是@otterb在对该问题的评论中提供了解决方案。 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." “ py2exe并不完美,因此经常会丢失一些需要的库或dll,pyd等。很可能是您缺少了opencv_highgui249.dl‌l和opencv_ffmpeg249.dll等。我会在没有启用单个可执行文件选项的情况下使用py2exe。而且,开始手动复制应用可能需要的文件。识别它们后,修改py2exe的setup.py,使其自动包含它们。”

I will note however that I use pyinstaller rather than py2exe, since I get fewer problems while building. 但是我会指出,我使用pyinstaller而不是py2exe,因为在构建时遇到的问题更少。 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. 我仍然必须手动复制opencv dll文件。在Windows 7上,它们位于以下位置:“ C:\\ Python27 \\ DLLs”,并且需要将它们复制到分发文件夹中,以便与其他dll位于同一路径上发行版附带的文件。

Try using pyinstaller , download it using pip : 尝试使用pyinstaller ,使用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: 如果您不知道如何安装pip,请尝试下载具有内置pip的python 2.7.9或更高版本,但不要忘记将python路径添加到环境变量中,本文中将提到此过程:

How to run Pip commands from CMD 如何从CMD运行Pip命令

After installing pyinstaller, select the main file of your project and run this command 安装pyinstaller后,选择项目的主文件并运行此命令

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 它将创建带有应用程序文件的文件夹并命名您的文件名,最后确保在运行该命令时,numpy和opencv位于C文件夹中python27的lib-> site-packages文件夹中

Hope it Helps! 希望能帮助到你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python脚本可执行文件与py2exe或pyinstaller - Python script executable with py2exe or pyinstaller Python 可执行文件:py2exe 还是 PyInstaller? - Python executables: py2exe or PyInstaller? 带有 VTK 的 Python 可执行文件……pyinstaller、py2exe、cx_freeze 等 - Python executable with VTK… pyinstaller, py2exe, cx_freeze etc 生成一个 Python 可执行文件(py2exe、pyinstaller 等),而没有许多子文件夹,如“tcl”等 - Producing a Python executable (py2exe, pyinstaller, etc.) wihtout lots of subfolders like “tcl”, etc 从python脚本创建独立可执行文件时包含批处理文件(py2exe) - Include batch file when creating a standalone executable from a python script (py2exe) 使用py2exe创建python可执行文件 - Creating a python executable using py2exe Python py2exe 可执行属性错误 - Python py2exe executable attributeerror 使用Py2exe将GUI转换为独立可执行文件时出错 - Error converting GUI to standalone executable using Py2exe py2exe / pyinstaller和DispatchWithEvents - py2exe/pyinstaller and DispatchWithEvents 如何将python 3.3脚本转换为可执行文件? 我找到了PyInstaller和py2exe,但是都不支持3.3。 - How can I turn a python 3.3 script into executable file? I found PyInstaller and py2exe, but both did not support 3.3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM