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?
As I thought what may be the case, the problem was due to Gunicorn being installed in a virtual environment. I uninstalled Gunicorn and this time skipped the steps in the guide that set up a virtual environment before re-installing Gunicorn. I also changed the myproject.service file from this:
to this:
Now I just need to wait for Google Domains to link the IP of the server to my domain which is freeaudioconverter.net
You may also add an additional path to PATH in [Service] Environment. This also works for uwsgi.
First check whether ffmpeg is installed by typing
if there is no error & you see version of ffmpeg then it's installed & if you see any error then install it
then check where is your ffmpeg executable by typing this command
output will be somthing like this
then copy this executable inside your virtualenv like this