我在Python 2.7中编写了一个应用程序,它使用moviepy检索媒体文件的长度。如果我从命令行运行它,一切正常;但冻结代码后,当我运行它时,控制台窗口立即关闭。我已经尝试过cx_freeze,pyinstaller和py2exe,都具有相同的结果。我的代码有问题或者这是moviepy的问题吗?我在Windows 10上进行测试,最终将在Windows 7上使用。这是代码:
#!/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()
答案 0 :(得分:1)
您可以从命令行运行冻结的代码以查看错误消息。
就pyinstaller而言,我无法在moviepy的hooks文件夹中看到一个钩子,很可能在冻结版本中没有捆绑。您可以将其添加(或其他任何可能遗漏的内容)作为隐藏导入:https://pythonhosted.org/PyInstaller/when-things-go-wrong.html?highlight=hidden#listing-hidden-imports