How to create exe file that includes cv module
I am writing a simple security camera program.
I used this code to access the camera:
import cv camera = cv.CaptureFromCAM(0)
I tried the .py file. It worked. But when I compiled and ran the exe file, I was unable to access the camera. The program did not respond. In a .py file, I could select a camera from a window called Video Source.
I think this issue is about access to authorities.
After that I opened the exe file through the "debug" function of visual studio 2010. I got this warning:
Unhandled exception at 0x02691fcb in security_camera.exe: 0xC0000005: Access violation writing location 0x00000000.
By the way, I got these outputs from the "output" tab:
'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).
By the way, when I open the exe file (program), it closes after 3-4 seconds.
How can I solve this? Thank.
Note: My python version is 2.7.3
I am using Windows 7 (32-bit)
Edit:
I created an exe file via py2exe.
My setup.py is like this:
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,
)
source to share
py2exe
Try insteadpyinstaller
Here are some simple instructions:
1) Install pyinstaller. If you have pip
, it's that simple:
pip install pyinstaller
2) Create your executable:
pyinstaller --onefile <your python script>
source to share