subprocess vs Pyinstaller for Windows
If you build .exe from command like this
pyinstaller --onefile --windowed your-script.py
Use subprocess
in script and DO NOT define stdin
or set to None.
Base on Windows workarounds of pyinstaller wiki.
Missing thing in many projects is not set stdin ( me too :/ ). This is very important if you want to use subprocess
and Pyinstaller
together. DO NOT leave stdin
None. Assign subprocess.PIPE
on it.
Example case
I want to convert flac file to mp3 by pydub and pack to exe by Pyinstaller.
from pydub import AudioSegmentsong = AudioSegment.from_file("my_song.flac", "flac")
song.export("my_song.mp3", format="mp3")
Simple.. But If you pack this script by Pyinstaller, Your script will freeze…. ️ ️Root cause is inside from_file
function in this case, stdin_parameter
is None.
But if I do same thing with from_file_using_tempory_files
…
from pydub import AudioSegmentsong = AudioSegment.from_file_using_temporary_files("my_song.flac", "flac")
song.export("my_song.mp3", format="mp3")
Yes, stdin
in from_file_using_tempory_files
is devnull
( not None ). Your script will not freeze. 🙌🙌