J'ai un programme python qui utilise la bibliothèque Opencv. Je veux exécuter ce programme sur le système d'exploitation Windows sans installer python lui-même. Donc, j'ai fait quelques recherches et j'ai trouvé Py2exe, mais j'ai du mal à l'utiliser. Voici mon code python:Py2exe tuple index out problème de plage pf lors de la création du fichier exe
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()
Et voici mon setup.py fichier:
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,
)
Chaque fois que j'utiliser la commande python setup.py py2exe ou tout simplement lancer la configuration du . py je reçois l'erreur suivante
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
Avez-vous essayé pyinstaller? – Stack
Oui, je l'ai essayé. J'ai un problème avec ça non plus! –
Cela fonctionne, juste vérifié. 'pyinstaller question.py --hidden-import = cv2' – Stack