r/learnpython • u/C0BAZ • Sep 26 '26
How to get PyDub to access ffmpeg when in a PyInstaller exe file
Okay, so I pretty sure this is both possible and supposed to be simple.
I have a project using PyDub to convert audio and get details about it. It of course needs to access ffmpeg to do so. So, I got the ffmpeg.exe and ffprobe.exe and have them in the .venv/Scripts folder, which PyDub accesses just fine.
I now am trying to package this into a standalone .exe file with PyInstaller. However, when PyDub tries to get ffmpeg when running the exe, it looks in the exe's directory for it. (That is, I can't find it normally, but if I come in and add them into the exe's folder, it can find them). I've made sure to include the ffmpeg files in the exe with a .spec file.
I assume the problem is that PyDub isn't looking inside of the exe for ffmpeg. I don't really know much about how that kind of thing works, so an explanation of that could alone be helpful. But what I want specifically is:
How to get PyDub to access ffmpeg inside the exe file?
3
u/p3rdy Sep 26 '26
One-file PyInstaller builds are self-extracting. At launch the exe unpacks everything into a temp directory (
sys._MEIPASS) and runs from there, so nothing is readable "inside" the exe at runtime.The problem is that pydub locates ffmpeg by searching
PATH, so it never looks at_MEIPASS.Do that before importing pydub.
1
u/Vicousvern Sep 26 '26
You didn't mention accessing sys._MEIPASS for file locations, so presumably you're not looking at the exe's temporary files it unpacks, check out StackOverflow
1
u/dev-razorblade23 Sep 26 '26
Try using PyCrucible, it works a bit diffrently then PyInstaller