os.system 用 pyinstaller 编译后不工作

os.system doesn't work after compiling with pyinstaller

我正在尝试获取在线视频的时长 使用 ffprobe

我的程序 运行 在我 运行 正常时完美,
但是,当我尝试使用 pyinstaller 将脚本编译为 exe
我点击它然后 os.system('ffprobe -i "{ URL Here}" -show_entries format=duration -v quiet -of csv="p=0"' > temp.txt') 似乎没有向文件输出任何内容,当 运行 使用非编译脚本时,它可以完美运行并执行预期的操作

import time
import re
import os, sys,tempfile
import eel
import ffmpy
import win32gui
import subprocess

eel.init('interface') # start the GUI

@eel.expose
def getDuration(url):
    duration = readcmd('ffprobe -i "{}" -show_entries format=duration -v quiet -of csv="p=0"'.format(url))
    # duration = subprocess.check_output(['ffprobe', '-i', url, '-show_entries', 'format=duration', '-v', 'quiet', '-of', 'csv=%s' % ("p=0")])
    return duration.rstrip()

def readcmd(cmd):
    os.system(cmd + " > temp.txt")
    data = ""
    with open('temp.txt', 'r') as file:
        data = file.read()
        file.close()
    os.remove('temp.txt')
    return data

eel.start('index.html', size=(1124, 768), mode = 'chrome') # Maybe I will implment Browser Fallback in the future

我看过这里 我已经尝试 运行ning pyinstaller
-w-noconsole 这是我的编译方式: python -m eel main.py interface --noconsole --add-binary "./ffmpeg.exe;./" --add-binary "./ffprobe.exe;./"

我正在使用 eel for gui

您可以使用auto-py-to-exe

使用 pip install auto-py-to-exe 和 运行 安装它,方法是在 cmd 中输入 auto-py-to-exe

请注意,这会生成一个文件夹,而不是据我所知的单个 .exe。有关更多信息,请访问 https://dev.to/eshleron/how-to-convert-py-to-exe-step-by-step-guide-3cfi

好吧,我花了 2 天的时间才弄明白,结果证明我有点笨。 问题是,当我使用 pyinstaller 构建时,我没有包含
ffmpeg 的 dll 文件,这导致它失败。 :) 请不要笑

为了解决我在使用 pyinstaller 时为每个 dll 添加 --add-data 的问题,现在它已经解决了。或者你可以手动复制dll文件到dist文件夹