Python Backend cannot use pydub/ffprobe in production

Anthony Nolletti 0 Reputation points
2024-03-27T21:18:52.8766667+00:00

I get the error below in production, not in development, when attempting to use the pydub library.

I am a relatively new fullstack developer and I use VSCode to automatically use Docker and upload to Azure.

It seems like ffprobe isn't found; however, it is included in my requirements.txt, along with pydub.

Profiler Installer is exiting as installation is completedEnding Log Tail of existing logs ---Starting Live Log Stream ---

2024-03-27T21:05:43.4049623Z warn("Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work", RuntimeWarning)

2024-03-27T21:05:43.4919891Z [2024-03-27 21:05:43,416] ERROR in app: Exception on /feedback_on_audio [POST]

2024-03-27T21:05:43.4932562Z Traceback (most recent call last):

2024-03-27T21:05:43.4941038Z File "/tmp/8dc4e778715d083/antenv/lib/python3.11/site-packages/flask/app.py", line 2190, in wsgi_app

2024-03-27T21:05:43.4949103Z response = self.full_dispatch_request()

2024-03-27T21:05:43.5018333Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

2024-03-27T21:05:43.5031494Z File "/tmp/8dc4e778715d083/antenv/lib/python3.11/site-packages/flask/app.py", line 1486, in full_dispatch_request

2024-03-27T21:05:43.5219047Z Transcription request made.

2024-03-27T21:05:43.5235303Z 174.118.230.220:54450 - - [27/Mar/2024:21:05:43 +0000] "POST /feedback_on_audio HTTP/1.1" 500 265 "http://localhost:3000/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"

2024-03-27T21:05:43.5302210Z rv = self.handle_user_exception(e)

2024-03-27T21:05:43.5318485Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

2024-03-27T21:05:43.5334019Z File "/tmp/8dc4e778715d083/antenv/lib/python3.11/site-packages/flask/app.py", line 1484, in full_dispatch_request

2024-03-27T21:05:43.5405049Z rv = self.dispatch_request()

2024-03-27T21:05:43.5420619Z ^^^^^^^^^^^^^^^^^^^^^^^

2024-03-27T21:05:43.5435109Z File "/tmp/8dc4e778715d083/antenv/lib/python3.11/site-packages/flask/app.py", line 1469, in dispatch_request

2024-03-27T21:05:43.5516272Z return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)

2024-03-27T21:05:43.5525298Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

2024-03-27T21:05:43.5533240Z File "/tmp/8dc4e778715d083/ai.py", line 60, in feedback_on_audio

2024-03-27T21:05:43.5599696Z transcription = transcribe(audio_file, language)

2024-03-27T21:05:43.5607822Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

2024-03-27T21:05:43.5615925Z File "/tmp/8dc4e778715d083/ai.py", line 126, in transcribe

2024-03-27T21:05:43.5625904Z audio = AudioSegment.from_file(io.BytesIO(audio_data))

2024-03-27T21:05:43.5791697Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

2024-03-27T21:05:43.5801780Z File "/tmp/8dc4e778715d083/antenv/lib/python3.11/site-packages/pydub/audio_segment.py", line 728, in from_file

2024-03-27T21:05:43.5810711Z info = mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)

2024-03-27T21:05:43.5819085Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

2024-03-27T21:05:43.5982678Z File "/tmp/8dc4e778715d083/antenv/lib/python3.11/site-packages/pydub/utils.py", line 274, in mediainfo_json

2024-03-27T21:05:43.5992950Z res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)

2024-03-27T21:05:43.6001662Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

2024-03-27T21:05:43.6012470Z File "/opt/python/3.11.7/lib/python3.11/subprocess.py", line 1026, in init

2024-03-27T21:05:43.6175875Z self._execute_child(args, executable, preexec_fn, close_fds,

2024-03-27T21:05:43.6186100Z File "/opt/python/3.11.7/lib/python3.11/subprocess.py", line 1950, in _execute_child

2024-03-27T21:05:43.6195215Z raise child_exception_type(errno_num, err_msg, err_filename)

2024-03-27T21:05:43.6202836Z FileNotFoundError: [Errno 2] No such file or directory: 'ffprobe'

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,775 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Konstantinos Passadis 17,126 Reputation points
    2024-03-28T11:56:34.5566667+00:00

    Hello @Anthony Nolletti

    Welcome to Microsoft QnA!

    Since you have docker you need to install the required packages

    This is not done through the requirements.txt file (which is for Python packages), but instead should be included in your Dockerfile. Here’s how you can modify your Dockerfile to install ffmpeg:

    DockerfileCopy code
    # Use an official Python runtime as a parent image
    FROM python:3.9-slim
    
    # ...
    
    # Install ffmpeg
    RUN apt-get update && \
        apt-get install -y ffmpeg && \
        apt-get clean
    
    # ...
    
    # Rest of your Dockerfile
    
    
    

    The requirements.txt file should include pydub, but not ffprobe or ffmpeg, as these are system packages, not Python packages.

    plaintextCopy code
    pydub==x.x.x
    # other python packages
    
    1. Verify PATH in Production Environment:

    Sometimes, the issue might be that the PATH environment variable in your Docker container doesn't include the location of ffprobe. Ensure that ffprobe is in the PATH. You can debug this by running a command in your Docker container to see if ffprobe is recognized:

    bashCopy code
    docker 
    

    --

    I hope this helps !

    The answer or portions of it may have been assisted by AI Source: ChatGPT Subscription

    Kindly mark any answer that helped you as Accepted and Upvote or post your feedback to provide additional help!

    Regards

    0 comments No comments