我如何告诉 Pyinstaller 使用 Scripts 文件夹中的 .EXE?

How do I tell Pyinstaller to use an .EXE thats in the Scripts folder?

例如如果我

pip install ffmpeg-python

和运行

os.system('ffmpeg -version')

它将打印 ffmpeg 的版本。

但是如果我将此行保存到 main.py 和 pyinstaller --onefile main.py 和 运行 它,Windows 找不到 ffmpeg。

如何告诉 pyinstaller 使用 Scripts 文件夹中的 ffmpeg.exe?

编辑:我想通了,在下面回答

我遇到了类似的问题。我通过定义本地目录的完整路径来解决它。之后,我将此路径添加到当前目录中的 EXE 文件和 运行 它们。所以试试这个:

from os import path
this_script_dir = path.dirname(path.realpath(__file__))
ffmpeg_path = this_script_dir + '\ffmpeg.exe'

好的,我就是这样做的:

#test.py
import sys
import os

if getattr(sys, 'frozen', False):
    basedir = sys._MEIPASS
else:
    basedir = os.path.dirname(os.path.abspath(file))
    basedir = str(basedir)

os.system(basedir+'/ffmpeg.exe -version') 
#works without the .exe also

并为您编写的 pyinstaller

pyinstaller test.py --add-data "ffmpeg.exe;." --onefile

ffmpeg.exe 与 test.py

在同一文件夹中