【问题标题】:How to build exe file which includes cv module如何构建包含 cv 模块的 exe 文件
【发布时间】:2015-07-13 00:48:57
【问题描述】:

我正在编写一个简单的安全摄像头程序。

我使用该代码访问相机:

import cv
camera = cv.CaptureFromCAM(0)

我尝试了 .py 文件。有效。但是,当我编译并运行 exe 文件时,我无法访问相机。程序没有反应。在 .py 文件中,我可以从标题为“视频源”的窗口中选择相机。

我认为这个关于访问权限的问题。

之后,我通过 Visual Studio 2010 的“调试”功能打开了 exe 文件。我收到了警告:

Unhandled exception at 0x02691fcb in security_camera.exe: 0xC0000005: Access violation writing location 0x00000000. 

顺便说一句,我从“输出”选项卡中得到了这些输出:

'security_camera.exe': Loaded '[file_path(C:\Users\........)]', Binary was not built with debug information.
'security_camera.exe': Loaded 'C:\Windows\System32\ntdll.dll', Cannot find or open the PDB file
'security_camera.exe': Loaded 'C:\Windows\System32\kernel32.dll', Cannot find or open the PDB file
'security_camera.exe': Loaded 'C:\Windows\System32\KernelBase.dll', Cannot find or open the PDB file
'security_camera.exe': Loaded 'C:\Windows\System32\user32.dll', Cannot find or open the PDB file
'security_camera.exe': Loaded 'C:\Windows\System32\gdi32.dll', Cannot find or open the PDB file
'security_camera.exe': Loaded 'C:\Windows\System32\lpk.dll', Cannot find or open the PDB file
'security_camera.exe': Loaded 'C:\Windows\System32\usp10.dll', Cannot find or open the PDB file
'security_camera.exe': Loaded 'C:\Windows\System32\msvcrt.dll', Cannot find or open the PDB file
'security_camera.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_50934f2ebcb7eb57\msvcr90.dll', Cannot find or open the PDB file
'security_camera.exe': Loaded 'C:\Windows\System32\imm32.dll', Cannot find or open the PDB file
'security_camera.exe': Loaded 'C:\Windows\System32\msctf.dll', Cannot find or open the PDB file
'security_camera.exe': Loaded 'C:\Windows\System32\nvinit.dll', Cannot find or open the PDB file
'security_camera.exe': Loaded 'C:\Windows\System32\advapi32.dll', Cannot find or open the PDB file
'security_camera.exe': Loaded 'C:\Windows\System32\sechost.dll', Cannot find or open the PDB file
'security_camera.exe': Loaded 'C:\Windows\System32\rpcrt4.dll', Cannot find or open the PDB file
'security_camera.exe': Loaded 'C:\Windows\System32\guard32.dll', Cannot find or open the PDB file
'security_camera.exe': Loaded 'C:\Windows\System32\version.dll', Cannot find or open the PDB file
'security_camera.exe': Loaded 'C:\Windows\System32\psapi.dll', Cannot find or open the PDB file
'security_camera.exe': Loaded 'C:\Windows\System32\fltLib.dll', Cannot find or open the PDB file
'security_camera.exe': Loaded 'C:\Windows\System32\shell32.dll', Cannot find or open the PDB file
'security_camera.exe': Loaded 'C:\Windows\System32\shlwapi.dll', Cannot find or open the PDB file
'security_camera.exe': Loaded 'C:\Windows\System32\winmm.dll', Cannot find or open the PDB file
'security_camera.exe': Loaded 'C:\Windows\System32\ole32.dll', Cannot find or open the PDB file
'security_camera.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7601.18201_none_ec80f00e8593ece5\comctl32.dll', Cannot find or open the PDB file
'security_camera.exe': Loaded 'C:\Windows\System32\oleaut32.dll', Cannot find or open the PDB file
'security_camera.exe': Loaded 'C:\Windows\System32\cryptsp.dll', Cannot find or open the PDB file
'security_camera.exe': Loaded 'C:\Windows\System32\rsaenh.dll', Cannot find or open the PDB file
'security_camera.exe': Loaded 'C:\Windows\System32\cryptbase.dll', Cannot find or open the PDB file
'security_camera.exe': Loaded 'C:\Windows\System32\ws2_32.dll', Cannot find or open the PDB file
'security_camera.exe': Loaded 'C:\Windows\System32\nsi.dll', Cannot find or open the PDB file
'security_camera.exe': Loaded 'C:\Windows\System32\comdlg32.dll', Cannot find or open the PDB file
First-chance exception at 0x02691fcb in security_camera.exe: 0xC0000005: Access violation writing location 0x00000000.
Unhandled exception at 0x02691fcb in security_camera.exe: 0xC0000005: Access violation writing location 0x00000000.
First-chance exception at 0x02691fcb in security_camera.exe: 0xC0000005: Access violation writing location 0x00000000.
Unhandled exception at 0x02691fcb in security_camera.exe: 0xC0000005: Access violation writing location 0x00000000.
First-chance exception at 0x02691fcb in security_camera.exe: 0xC0000005: Access violation writing location 0x00000000.
Unhandled exception at 0x02691fcb in security_camera.exe: 0xC0000005: Access violation writing location 0x00000000.
First-chance exception at 0x02691fcb in security_camera.exe: 0xC0000005: Access violation writing location 0x00000000.
Unhandled exception at 0x02691fcb in security_camera.exe: 0xC0000005: Access violation writing location 0x00000000.
First-chance exception at 0x02691fcb in security_camera.exe: 0xC0000005: Access violation writing location 0x00000000.
Unhandled exception at 0x02691fcb in security_camera.exe: 0xC0000005: Access violation writing location 0x00000000.
First-chance exception at 0x02691fcb in security_camera.exe: 0xC0000005: Access violation writing location 0x00000000.
Unhandled exception at 0x02691fcb in security_camera.exe: 0xC0000005: Access violation writing location 0x00000000.
First-chance exception at 0x02691fcb in security_camera.exe: 0xC0000005: Access violation writing location 0x00000000.
Unhandled exception at 0x02691fcb in security_camera.exe: 0xC0000005: Access violation writing location 0x00000000.
First-chance exception at 0x02691fcb in security_camera.exe: 0xC0000005: Access violation writing location 0x00000000.
Unhandled exception at 0x02691fcb in security_camera.exe: 0xC0000005: Access violation writing location 0x00000000.
First-chance exception at 0x02691fcb in security_camera.exe: 0xC0000005: Access violation writing location 0x00000000.
Unhandled exception at 0x02691fcb in security_camera.exe: 0xC0000005: Access violation writing location 0x00000000.
First-chance exception at 0x02691fcb in security_camera.exe: 0xC0000005: Access violation writing location 0x00000000.
Unhandled exception at 0x02691fcb in security_camera.exe: 0xC0000005: Access violation writing location 0x00000000.
First-chance exception at 0x02691fcb in security_camera.exe: 0xC0000005: Access violation writing location 0x00000000.
Unhandled exception at 0x02691fcb in security_camera.exe: 0xC0000005: Access violation writing location 0x00000000.
The program '[8604] security_camera.exe: Native' has exited with code -1073741819 (0xc0000005).

顺便说一句,当我打开 exe 文件(程序)时,它会在 3-4 秒内关闭。

我该如何解决?谢谢。

注意: 我的python版本:2.7.3

我使用的是 Windows 7(32 位)

编辑:

我通过py2exe构建了exe文件。

我的 setup.py 是这样的:

from distutils.core import setup
import py2exe, sys, os

sys.argv.append('py2exe')

setup(
    options = {'py2exe': {'bundle_files': 1, 'compressed': True, 'includes': 'numpy'}},
    windows = [{'script': "security_camera.py"}],
    zipfile = None,
)

【问题讨论】:

  • 我是用 py2exe 构建的。我的设置文件是: from distutils.core import setup import py2exe, sys, os sys.argv.append('py2exe') setup( options = {'py2exe': {'bundle_files': 1, 'compressed': True, 'includes': 'numpy'}}, windows = [{'script': "security_camera.py"}], zipfile = None, )
  • 不相关,但您应该使用 cv2 而不是已弃用的 cv 模块
  • 但是,我使用了来自互联网的代码。我是从互联网上找到它们的。在来自互联网的代码中,程序员(编写这些代码)使用了 cv 模块。 cv的用法和cv2的用法不一样,不知道怎么把这些代码转成cv2。
  • 只知道,这个api在opencv3.0中被删除了。

标签: python opencv camera py2exe pyinstaller


【解决方案1】:

试试pyinstaller,而不是py2exe

这里有一些简单的说明:

1) 安装 pyinstaller。如果你有pip,就这么简单:

pip install pyinstaller

2) 创建你的可执行文件:

pyinstaller --onefile <your python script>

【讨论】:

  • 我已经试过了。但是,它没有用。当我打开它时,出现错误:ImportError: numpy.core.multiarray failed to import
  • @python_pardus 谷歌搜索该错误会给出几个结果,我不知道它们是否与您的情况相关。但我会尝试走这条路,导入错误可能比段错误更容易解决。
  • 对不起,“seg”是什么意思?我不是本地人。
  • @python_pardus 作为本地人无济于事 :) 这是“分段”的缩写,segmentation fault,Visual Studio 似乎报告您正在尝试访问地址 0x00000000 的内存,即不是有效的地址。
  • 好的。我得到了它。如何解决段错误?如果我使用pyinstaller没有错误( ImportError: numpy.core.multiarray failed to import),我可以解决它。
【解决方案2】:

@Antonio 我通过添加解决了关于 pyinstaller 的问题

import numpy

到我的脚本。我通过pyinstaller构建了exe。我打开了exe文件。但是,它什么也没做。它只是等待。

我该怎么办?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-28
    • 1970-01-01
    相关资源
    最近更新 更多