2016-07-21 3 views
0

나는 moviepy를 사용하여 미디어 파일의 길이를 검색하는 Python 2.7의 앱을 작성했습니다. 명령 줄에서 실행하면 모든 것이 잘 작동합니다. 하지만 코드를 고정시킨 후 실행하면 즉시 콘솔 창이 닫힙니다. 나는 cx_freeze, pyinstaller 및 py2exe를 모두 같은 결과로 시도했다. 내 코드에 문제가 있습니까? 아니면 moviepy 문제입니까? Windows 10에서 테스트 중이며, 결국 Windows 7에서 사용됩니다. 코드는 다음과 같습니다.Python - 코드가 고정 된 후 콘솔이 닫힙니다.

#!/usr/bin/python 
# -*- coding: utf-8 -*- 

# Video-Audio Length Retriever 
# 
# Version: 0719A 
# 
# Author: Simon Lachaîne 


import codecs 
from moviepy.editor import VideoFileClip, AudioFileClip 
import os 


directories = [] 


def read_directories(): 
    global directories 
    directories_txt = raw_input("Enter the path and name of the text file containing the source directories: ") 

    with codecs.open(directories_txt, "r", encoding="utf8") as source_dirs: 
     directories = [line.rstrip() for line in source_dirs] 


def write_text(report, text2save): 
    with open(report, "a") as report: 
     report.write(text2save) 


def check_duration(): 
    for directory in directories: 
     for root, dirs, files in os.walk(directory): 
      os.chdir(root) 
      for fichier in files: 

       try: 
        video = VideoFileClip(fichier) 

        m, s = divmod(video.duration, 60) 
        h, m = divmod(m, 60) 

        length = fichier + " ; " + "%02d:%02d:%02d\n" % (h, m, s) 
        write_text(durations_report, length) 
        print "Processed file " + fichier 

       except IOError: 
        pass 

       except KeyError: 
        try: 
         audio = AudioFileClip(fichier) 

         m, s = divmod(audio.duration, 60) 
         h, m = divmod(m, 60) 

         length = fichier + " ; " + "%02d:%02d:%02d\n" % (h, m, s) 
         write_text(durations_report, length) 
         print "Processed file " + fichier 

        except IOError: 
         pass 


read_directories() 
durations_report = raw_input("Enter the path and name of the report to create: ") 
check_duration() 

답변

1

오류 메시지를 보려면 명령 줄에서 고정 된 코드를 실행할 수 있습니다.

pyinstaller에 관해서는 moviepy 용 hooks 폴더에서 후크를 볼 수 없으며 대부분 고정 된 버전에서 번들되지 않았습니다. 숨겨진 가져 오기로 누락 된 항목 (또는 누락 된 항목)을 추가 할 수 있습니다. https://pythonhosted.org/PyInstaller/when-things-go-wrong.html?highlight=hidden#listing-hidden-imports

+0

답장을 보내 주셔서 감사합니다. 오류는 "시스템이 moviepy \ video \ fx로 연결되는 지정된 경로를 찾을 수 없습니다"입니다. 따라서 moviepy가 고정 된 응용 프로그램에 포함되어 있지 않은 것 같습니다. 나는 cx_freeze에 대한 나의 설정 스크립트에서 그것을 지정했다. 나는 pyinstaller와 똑같이하려고 노력할 것이다. 내 문제를 해결할 수단을 제게 제공 한 이후로 제 질문에 대한 답을 생각해보십시오. –