具有独立python可执行文件(py2exe/pyinstaller)的OpenCV [英] OpenCV with standalone python executable (py2exe/pyinstaller)

查看:122
本文介绍了具有独立python可执行文件(py2exe/pyinstaller)的OpenCV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用OpenCV从视频文件中获取帧进行处理的python程序.然后,我使用py2exe创建一个独立的可执行文件(也尝试使用pyinstaller并出现相同的错误).我的计算机和目标计算机都是Windows 7,但目标计算机未安装python.我使用OpenCV从视频文件中读取帧速率和单个图像.

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.

问题:当我在目标计算机上运行可执行文件时,帧速率返回为0.0,而我无法读取帧.

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

如果在目标计算机上安装了python,则可执行文件会按预期运行,否则会产生此错误.因此,似乎可执行文件中缺少某些内容,但是在创建可执行文件以指示可能缺少的内容时,我没有收到任何错误消息.

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.

其他报告过类似问题的人通常不包括numpy依赖项(并得到指示此错误的信息),但我包括了numpy.我也尝试过包括整个PyQt4模块,因为它被列为OpenCV的python xy站点上的依赖项(我对代码的其他部分已经有了PyQt4的某些部分),但这也不能解决问题.

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.

推荐答案

尝试使用pyinstaller,并使用pip进行下载:

Try using pyinstaller, download it using pip :

pip install pyinstaller

如果您不知道如何安装pip,请尝试下载具有内置pip的python 2.7.9或更高版本,但不要忘记将python路径添加到环境变量中,本文中将提到此过程:

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:

如何从CMD运行Pip命令

在安装pyinstaller之后,选择项目的主文件并运行此命令

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

pyinstaller yourprogram.py

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

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

希望有帮助!

这篇关于具有独立python可执行文件(py2exe/pyinstaller)的OpenCV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆