2017-06-15 10 views
0

私はOpencvライブラリを使用するpythonプログラムを持っています。私はPython自体をインストールせずにWindowsオペレーティングシステム上でこのプログラムを実行したい。だから、私はいくつかの調査を行い、Py2exeを見つけましたが、私はそれを使用して問題があります。ここ は私のpythonのコードです:私はpythonのsetup.py py2exeコマンドを使用するか、単にセットアップを実行するたびにexeファイルを作成するときにPy2exeタプルのインデックスアウトpfの範囲の問題

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

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

そして、ここでは私のsetup.pyファイルです。 py次のエラーが発生する

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

pyinstallerを試しましたか? – Stack

+0

はい、私はそれを試しました。いずれかに問題があります! –

+0

これは機能しています。 'pyinstaller question.py --hidden-import = cv2' – Stack

答えて

0

次の行を追加してください:

import numpy 

スクリプトの先頭に行を追加してください。 numpyの依存関係が検出されないことがある

関連する問題