2017-06-15 1 views
0

Ich habe Python-Programm, das Opencv-Bibliothek verwendet. Ich möchte dieses Programm auf Windows-Betriebssystem ausführen, ohne Python selbst zu installieren. Also habe ich ein paar Nachforschungen angestellt und Py2exe gefunden, aber ich habe Probleme damit. Hier ist mein Python-Code:Py2exe Tuple-Index out pf Bereichsproblem beim Erstellen von EXE-Datei

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() 

Und hier ist mein setup.py Datei:

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, 
) 

Immer, wenn ich Python setup.py py2exe Befehl verwenden oder einfach Setup ausführen. py ich bekomme den folgenden fehler

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

+0

Haben Sie Pyinstaller probiert? – Stack

+0

Ja, ich habe es versucht. Habe auch ein Problem damit! –

+0

Dies funktioniert, nur überprüft. 'pyinstaller question.py --hidden-import = cv2' – Stack

Antwort

0

Probieren Sie die Zeile hinzufügen:

import numpy 

im Anfang des Skripts. Die numpige Abhängigkeit wird manchmal nicht erkannt