Python cannot find a file that is definitely there

Question:

I am trying to upload an MP3 file and play it using pydub:

import pydub
from pydub import AudioSegment
from pydub.playback import play

blast_file = AudioSegment.from_mp3(
                                   "C:/Users/am650/Downloads/radio_static.mp3")

From this, I get the following error:

C:Usersam650PycharmProjectspythonProjectvenvScriptspython.exe C:Usersam650PycharmProjectspythonProjectcrtt_control.py 
C:Usersam650PycharmProjectspythonProjectvenvLibsite-packagespydubutils.py:170: RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work
  warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work", RuntimeWarning)
C:Usersam650PycharmProjectspythonProjectvenvLibsite-packagespydubutils.py:198: RuntimeWarning: Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work
  warn("Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work", RuntimeWarning)
Traceback (most recent call last):
  File "C:Usersam650PycharmProjectspythonProjectcrtt_control.py", line 38, in <module>
    blast_file = AudioSegment.from_mp3(
                 ^^^^^^^^^^^^^^^^^^^^^^
  File "C:Usersam650PycharmProjectspythonProjectvenvLibsite-packagespydubaudio_segment.py", line 796, in from_mp3
    return cls.from_file(file, 'mp3', parameters=parameters)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:Usersam650PycharmProjectspythonProjectvenvLibsite-packagespydubaudio_segment.py", line 728, in from_file
    info = mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:Usersam650PycharmProjectspythonProjectvenvLibsite-packagespydubutils.py", line 274, in mediainfo_json
    res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:Usersam650AppDataLocalProgramsPythonPython311Libsubprocess.py", line 1024, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:Usersam650AppDataLocalProgramsPythonPython311Libsubprocess.py", line 1493, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [WinError 2] The system cannot find the file specified

Process finished with exit code 1

I have messed around with forward and back slashes, I tried putting r in front of the file call (r"C:/Users/am650/Downloads/radio_static.mp3"), I have moved the file to different locations, etc. I have also tried other files and file types. It seems that python cannot find any file of mine…

I originally wrote this code on a mac (where it worked fine) and moved it to a PC. This error is occurring on the PC (windows 10). I am using Python 3.11.1 and I only have one version of Python downloaded. I had a similar problem earlier where Python would not recognise any of my pip installs, but I got around this by adding the packages directly in pycharm using PyPl. I now wounder if these two issues are related?

It is also worth noting that I am using a school computer that was configured such that all downloads automatically save to one drive, not the local computer. I have moved python (and the audio file) to the computer drive but maybe I have missed a file somewhere? I do not have another PC on which I can test these theories, and my IT department took a look and could not figure it out.

Asked By: grace.cutler

||

Answers:

If you look closely to the error trace you will find that the problem is not in your file but in the program. According the source it looks for the exe in the local folder or in the system PATH folders. Probably you forgot to copy ffmpeg.exe into your program folder.

Answered By: viilpe
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.