0

I have python program that uses Opencv library. I want to run this program on windows operating system without installing python itself. So , I did some research and found Py2exe, but i have problem using it. Here is my python code :

import cv2
import os


# Custom Car Cascade Classifier
car_cascade = cv2.CascadeClassifier("Custom-Car-Cascade.xml")

#Get Test Images Folder From Current Running Path
directory = 'TestImages'
print(directory)
for file in os.listdir(directory):
        if file.endswith(".jpg"):
                #Red Image Into img
                img = cv2.imread(directory + "/" + file,cv2.IMREAD_COLOR)
                #Get Detected Cars Point On Image
                cars = car_cascade.detectMultiScale(img,1.4,10)
                for(x,y,w,h) in cars:
                    #Draw Rectangle 
                    cv2.rectangle(img,(x,y),(x+w,y+h),(255,255,0),2)
                #Creat Window
                cv2.namedWindow("output", cv2.WINDOW_NORMAL)
                #Resize Image
                resized = cv2.resize(img, (800, 600))
                #Show Image
                cv2.imshow("output",resized)
                k = cv2.waitKey() & 0xff
                if(k == 27):
                    break
cv2.destroyAllWindows()

And here is my setup.py file :

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

sys.argv.append('py2exe')

setup(
    options = {'py2exe': {'bundle_files': 1, 'compressed':     True,'includes':'cv2'}},
    windows = [{'script': "carDetection.py"}],
    #data_files=[("TestImages", "TestImages/*.jpg")],
    zipfile = None,
)

Whenever i use python setup.py py2exe command or just simply run setup.py i get the following error

Traceback (most recent call last): File "C:\Users\Hadi\AppData\Local\Programs\Python\Python36-32\Program1\setup.py", line 10, in zipfile = None, File "C:\Users\Hadi\AppData\Local\Programs\Python\Python36-32\lib\distutils\core.py", line 148, in setup dist.run_commands() File "C:\Users\Hadi\AppData\Local\Programs\Python\Python36-32\lib\distutils\dist.py", line 955, in run_commands self.run_command(cmd) File "C:\Users\Hadi\AppData\Local\Programs\Python\Python36-32\lib\distutils\dist.py", line 974, in run_command cmd_obj.run() File "C:\Users\Hadi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\distutils_buildexe.py", line 188, in run self._run() File "C:\Users\Hadi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\distutils_buildexe.py", line 267, in _run builder.analyze() File "C:\Users\Hadi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\runtime.py", line 158, in analyze self.mf.import_package(modname[:-2]) File "C:\Users\Hadi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\mf3.py", line 92, in import_package self.import_hook(name) File "C:\Users\Hadi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\mf3.py", line 120, in import_hook module = self._gcd_import(name) File "C:\Users\Hadi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\mf3.py", line 274, in _gcd_import return self._find_and_load(name) File "C:\Users\Hadi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\mf3.py", line 357, in _find_and_load self._scan_code(module.code, module) File "C:\Users\Hadi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\mf3.py", line 388, in _scan_code for what, args in self._scan_opcodes(code): File "C:\Users\Hadi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\mf3.py", line 417, in _scan_opcodes yield "store", (names[oparg],) IndexError: tuple index out of range

Eliethesaiyan
  • 2,327
  • 1
  • 22
  • 35
Hadi Mohammadi
  • 314
  • 2
  • 5
  • 20

1 Answers1

0

Try to add the line :

import numpy

in the top of your script. The numpy dependency is sometime not detected

Anthony Rossi
  • 1,182
  • 8
  • 14