0

我用 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()
4

1 回答 1

1

您可以从命令行运行冻结的代码以查看错误消息。

就 pyinstaller 而言,我在 hooks 文件夹中看不到moviepy 的钩子,而且很可能它没有捆绑在冻结版本中。您可以将它(或任何其他可能缺少的内容)添加为隐藏导入:https ://pythonhosted.org/PyInstaller/when-things-go-wrong.html?highlight=hidden#listing-hidden-imports

于 2016-07-22T13:20:25.350 回答