2

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?

1
  • Try using full paths for lame and wine. Looks like a classic case of a different $PATH in whatever environment they are running in.
    – user535733
    Feb 6, 2020 at 4:47

3 Answers 3

1

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:

[Unit]
Description=Gunicorn instance to serve myproject
After=network.target

[Service]
User=ubuntu
Group=www-data
WorkingDirectory=/home/ubuntu/myproject
Environment="PATH=/home/ubuntu/myproject/myprojectenv/bin"
ExecStart=/home/ubuntu/myproject/myprojectenv/bin/gunicorn --workers 3 --bind unix:myproject.sock -m 007 wsgi:app

to this:

[Unit]
Description=Gunicorn instance to serve myproject
After=network.target

[Service]
User=ubuntu
Group=www-data
WorkingDirectory=/home/ubuntu/myproject
ExecStart=/home/ubuntu/myproject/bin/gunicorn --workers 3 --bind unix:myproject.sock -m 007 wsgi:app

Now I just need to wait for Google Domains to link the IP of the server to my domain which is freeaudioconverter.net

1
  • problem was that in the .service file you were overriding PATH. Instead of PATH=/home/ubuntu/myproject/myprojectenv/bin you should have used something like PATH=/home/ubuntu/myproject/myprojectenv/bin:$PATH. Jan 11, 2021 at 22:00
1

You may also add an additional path to PATH in [Service] Environment. This also works for uwsgi.

[Service]
Environment="PATH=/home/ubuntu/myproject/myprojectenv/bin:/usr/bin"
0

First check whether ffmpeg is installed by typing

$ ffmpeg -version

if there is no error & you see version of ffmpeg then it's installed & if you see any error then install it

$ sudo apt update
$ sudo apt install ffmpeg

then check where is your ffmpeg executable by typing this command

$ which ffmpeg

output will be somthing like this

/usr/bin/ffmpeg

then copy this executable inside your virtualenv like this

$ sudo cp /usr/bin/ffmpeg /my_project/my_env/bin/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .