Background: I'm trying to make an application that plays music via a GUI (Tkinter), Youtube_DL and FFmpeg. While the actual application is done it also requires FFmpeg to be an environment variable to work. Now, I'm trying to foolproof the creation of a "personal" FFmpeg environment variable in order to make the application portable (the last step is using pyinstaller to make a .exe file).
Problem:
I'm trying to create the environment variable for FFmpeg by passing SET
through subprocess.Popen
:
add_ffmpeg = subprocess.Popen(f"IF EXIST {path2set} SET PATH=%PATH%;{path2set}", shell=True)
When I try to echo %PATH%
(with Popen
) the FFmpeg variable that should be present, is not. I just need to know whether or not I'm wasting my time with SET
and should instead be using SETX
or perhaps some other solution, I'm open to being told I did this all wrong.
Relevant Code:
# get any sub-directory with ffmpeg in it's name
ffmpeg = glob(f"./*ffmpeg*/")
# proceed if there is a directory
if len(ffmpeg) > 0:
# double-check directory exists
ffmpeg_exist = path.isdir(ffmpeg[0])
if ffmpeg_exist:
print("FFmpeg: Found -> Setting Up")
# get the absolute path of the directories bin folder ".\ffmpeg-release-essentials.zip\bin"
path2set = f"{path.abspath(ffmpeg[0])}\\bin\\"
# add path of directory to environment variables
add_ffmpeg = subprocess.Popen(f"IF EXIST {path2set} SET PATH=%PATH%;{path2set}", shell=True)
add_ffmpeg.wait()
# print all of the current environment variables
list_vars = subprocess.Popen("echo %PATH%", shell=True)
list_vars.wait()
else:
print("FFmpeg: Missing -> Wait for Download...")
# download the ffmpeg file via direct link
wget.download("https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-essentials.zip")
# unzip the file
powershell = subprocess.Popen("powershell.exe Expand-Archive -Path './ffmpeg-release-essentials.zip' "
"-DestinationPath './'")
powershell.wait()
# remove the file
remove("./ffmpeg-release-essentials.zip")
# get any sub-directory with ffmpeg in it's name
ffmpeg = glob("./*ffmpeg*/")
# double-check directory exists
ffmpeg_exist = path.isdir(ffmpeg[0])
# proceed with if it exists
if ffmpeg_exist:
print("FFmpeg: Found -> Setting Up")
# get the absolute path of the directories bin folder ".\ffmpeg-release-essentials.zip\bin"
path2set = f"{path.abspath(ffmpeg[0])}\\bin\\"
# add path of directory to environment variables
add_ffmpeg = subprocess.Popen(f"IF EXIST {path2set} SET PATH=%PATH%;{path2set}", shell=True)
add_ffmpeg.wait()
# print all of the current environment variables
list_vars = subprocess.Popen("echo %PATH%", shell=True)
list_vars.wait()
else:
print("Something unexplained has gone wrong.")
exit(0)