I am experiencing a very strange problem. I made a website and I am having a problem with the backend. It's running on an Ubuntu 18.04 server. The backend is written in Python and Flask (a micro web framework). I have set up Nginx and Gunicorn as it is not recommended to use Flask's built-in development server.
I have set up Nginx and Gunicorn correctly using this guide. This is not the problem. My website is an audio converter which uses FFmpeg and various encoders such as LAME. So it requires commands to be run in the Terminal. As an example, when Python tries to do:
os.system('wine ~/.wine/drive_c/ffmpeg.exe -i "1.wav" -ac 2 -vn -f wav - | lame -b 320 - "12345".mp3')
I see the following error in the logs:
gunicorn[2311]: sh: 1: lame: not found
gunicorn[2311]: sh: 1: wine: not found
I have even tried using subprocess instead of os.system, using the following command:
subprocess.run('wine ~/.wine/drive_c/ffmpeg.exe -i "1.wav" -ac 2 -vn -f wav - | lame -b 320 - "12345".mp3', shell=True)
But I get the same errors.
The thing is, lame and wine can be accessed fine. And to prove my point, if I run the EXACT same command directly in the Terminal, i.e.:
wine ~/.wine/drive_c/ffmpeg.exe -i "1.wav" -ac 2 -vn -f wav - | lame -b 320 - "12345".mp3
I get no errors and the 1.wav file successfully gets converted to MP3.
Why am I getting those errors when Python tries to run those commands?
**EDIT: I've been thinking and maybe this is the issue: Gunicorn was set up in a virtual environment as I followed this tutorial. LAME and Wine might not installed in the virtual environment? Maybe that's why when I run my Python/Flask app with Gunicorn, it doesn't know what they are? Is there a way I can check whether this is the case?