I’m having a similar issue on Python 3.8.7, and I can’t find the solution.
In my project, I’m using pydub.AudioSegment to get audio from a file and then exporting that audio in a different format. My code works perfectly when I’m running the python file directly. However, when I convert it to an executable with pyinstaller, run the program and get to the point of importing the audio with pydub, it gives me the following error:
Traceback (most recent call last): File "main.py", line 269, in <module> File "main.py", line 213, in convertfile File "main.py", line 133, in cloud_upload File "pydubaudio_segment.py", line 728, in from_file File "pydubutils.py", line 274, in mediainfo_json File "subprocess.py", line 804, in __init__ File "subprocess.py", line 1142, in _get_handles OSError: [WinError 6] The handle is invalid
pydub call in my program looks like this:
sound = AudioSegment.from_file(filepath) sound.export(new_filepath, format="ogg",codec='libopus')
I’ve tried to add stdin=subprocess.DEVNULL and stdin=subprocess.PIPE in utils.py on line 274, but that didn’t work either. Maybe I added them incorrectly, though, so suggestions like that are also highly appreciated.
I’ve managed to solve the problem only by removing –onefile option from pyinstaller and dropping ffmpeg.exe and ffprobe.exe into the resulted folder with the main.exe file.
That’s not a good solution to the problem as I’d still prefer to use
--onefile; but it works.
I’m still open to suggestions on how to make it work with –onefile or just generally why this is hapenning.