Home > Mobile >  Python cannot find a file that is definitely there
Python cannot find a file that is definitely there

Time:01-14

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:\Users\am650\PycharmProjects\pythonProject\venv\Scripts\python.exe C:\Users\am650\PycharmProjects\pythonProject\crtt_control.py 
C:\Users\am650\PycharmProjects\pythonProject\venv\Lib\site-packages\pydub\utils.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:\Users\am650\PycharmProjects\pythonProject\venv\Lib\site-packages\pydub\utils.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:\Users\am650\PycharmProjects\pythonProject\crtt_control.py", line 38, in <module>
    blast_file = AudioSegment.from_mp3(
                 ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\am650\PycharmProjects\pythonProject\venv\Lib\site-packages\pydub\audio_segment.py", line 796, in from_mp3
    return cls.from_file(file, 'mp3', parameters=parameters)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\am650\PycharmProjects\pythonProject\venv\Lib\site-packages\pydub\audio_segment.py", line 728, in from_file
    info = mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\am650\PycharmProjects\pythonProject\venv\Lib\site-packages\pydub\utils.py", line 274, in mediainfo_json
    res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\am650\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 1024, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\am650\AppData\Local\Programs\Python\Python311\Lib\subprocess.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.

CodePudding user response:

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.

  • Related