0
我在Python 2.7中編寫了一個應用程序,它使用moviepy檢索媒體文件的長度。如果我從命令行運行它,一切正常;但在凍結代碼後,當我運行它時,控制檯窗口立即關閉。我試過cx_freeze,pyinstaller和py2exe,所有結果都一樣。我的代碼有問題嗎?或者這對於影片有問題?我正在測試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()
謝謝您的回答。錯誤是「系統找不到指定的路徑」,導致了moviepy \ video \ fx,所以問題似乎是moviepy沒有包含在凍結的應用程序中。我已經在cx_freeze的設置腳本中指定了它,我將嘗試在pyinstaller中執行相同的操作。考慮到我的問題,因爲你提供瞭解決問題的方法。 –