question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OSError: file not found

See original GitHub issue

Description

Description

I face a problem when I follow the tutorial:

# Beat tracking example
from __future__ import print_function
import librosa

# 1. Get the file path to the included audio example
filename = librosa.util.example_audio_file()

# 2. Load the audio as a waveform `y`
#    Store the sampling rate as `sr`
y, sr = librosa.load(filename)

# 3. Run the default beat tracker
tempo, beat_frames = librosa.beat.beat_track(y=y, sr=sr)

print('Estimated tempo: {:.2f} beats per minute'.format(tempo))

# 4. Convert the frame indices of beat events into timestamps
beat_times = librosa.frames_to_time(beat_frames, sr=sr)

print('Saving output to beat_times.csv')
librosa.output.times_csv('beat_times.csv', beat_times)


Steps/Code to Reproduce

Expected Results

It may run without error

Actual Results

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/zhongyi/anaconda3/envs/tf-torch/lib/python3.6/site-packages/librosa/core/audio.py", line 119, in load
    with audioread.audio_open(os.path.realpath(path)) as input_file:
  File "/home/zhongyi/anaconda3/envs/tf-torch/lib/python3.6/site-packages/audioread/__init__.py", line 111, in audio_open
    return ffdec.FFmpegAudioFile(path)
  File "/home/zhongyi/anaconda3/envs/tf-torch/lib/python3.6/site-packages/audioread/ffdec.py", line 150, in __init__
    self._get_info()
  File "/home/zhongyi/anaconda3/envs/tf-torch/lib/python3.6/site-packages/audioread/ffdec.py", line 206, in _get_info
    raise IOError('file not found')
OSError: file not found

Versions

>>> import platform; print(platform.platform())
Linux-4.15.0-51-generic-x86_64-with-debian-buster-sid
>>> import sys; print("Python", sys.version)
Python 3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 12:22:00) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
>>> import numpy; print("NumPy", numpy.__version__)
NumPy 1.13.3
>>> import scipy; print("SciPy", scipy.__version__)
SciPy 1.1.0
>>> import librosa; print("librosa", librosa.__version__)
librosa 0.6.3

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:27 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
bmcfeecommented, May 1, 2021

Are you sure that the file exists?

0reactions
jmostrom013commented, Apr 30, 2021

Hi, I am getting this same problem as well, a file not found error. I tried installing in a conda environment using conda install -c conda-forge librosa. I also made sure that ffmpeg is installed (4.3.1). Here’s the full message:

/Users/janetmostrom/miniconda3/envs/torch/lib/python3.9/site-packages/librosa/core/audio.py:162: UserWarning: PySoundFile failed. Trying audioread instead.
  warnings.warn("PySoundFile failed. Trying audioread instead.")
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
~/miniconda3/envs/torch/lib/python3.9/site-packages/librosa/core/audio.py in load(path, sr, mono, offset, duration, dtype, res_type)
    145     try:
--> 146         with sf.SoundFile(path) as sf_desc:
    147             sr_native = sf_desc.samplerate

~/miniconda3/envs/torch/lib/python3.9/site-packages/soundfile.py in __init__(self, file, mode, samplerate, channels, subtype, endian, format, closefd)
    628                                          format, subtype, endian)
--> 629         self._file = self._open(file, mode_int, closefd)
    630         if set(mode).issuperset('r+') and self.seekable():

~/miniconda3/envs/torch/lib/python3.9/site-packages/soundfile.py in _open(self, file, mode_int, closefd)
   1182             raise TypeError("Invalid file: {0!r}".format(self.name))
-> 1183         _error_check(_snd.sf_error(file_ptr),
   1184                      "Error opening {0!r}: ".format(self.name))

~/miniconda3/envs/torch/lib/python3.9/site-packages/soundfile.py in _error_check(err, prefix)
   1356         err_str = _snd.sf_error_number(err)
-> 1357         raise RuntimeError(prefix + _ffi.string(err_str).decode('utf-8', 'replace'))
   1358 

RuntimeError: Error opening '~/machine_learning_class/cats_dogs/train/dog/dog_barking_0.wav': System error.

During handling of the above exception, another exception occurred:

FileNotFoundError                         Traceback (most recent call last)
<ipython-input-2-4728a8f3fa65> in <module>
      7 train_dog_path = "~/machine_learning_class/cats_dogs/train/dog/"
      8 
----> 9 x, fs = librosa.load(train_dog_path+"dog_barking_0.wav")

~/miniconda3/envs/torch/lib/python3.9/site-packages/librosa/core/audio.py in load(path, sr, mono, offset, duration, dtype, res_type)
    161         if isinstance(path, (str, pathlib.PurePath)):
    162             warnings.warn("PySoundFile failed. Trying audioread instead.")
--> 163             y, sr_native = __audioread_load(path, offset, duration, dtype)
    164         else:
    165             raise (exc)

~/miniconda3/envs/torch/lib/python3.9/site-packages/librosa/core/audio.py in __audioread_load(path, offset, duration, dtype)
    185 
    186     y = []
--> 187     with audioread.audio_open(path) as input_file:
    188         sr_native = input_file.samplerate
    189         n_channels = input_file.channels

~/miniconda3/envs/torch/lib/python3.9/site-packages/audioread/__init__.py in audio_open(path, backends)
    109     for BackendClass in backends:
    110         try:
--> 111             return BackendClass(path)
    112         except DecodeError:
    113             pass

~/miniconda3/envs/torch/lib/python3.9/site-packages/audioread/rawread.py in __init__(self, filename)
     60     """
     61     def __init__(self, filename):
---> 62         self._fh = open(filename, 'rb')
     63 
     64         try:

FileNotFoundError: [Errno 2] No such file or directory: '~/machine_learning_class/cats_dogs/train/dog/dog_barking_0.wav'


Read more comments on GitHub >

github_iconTop Results From Across the Web

OSError: file not found - python - Stack Overflow
I had this same issue. It cannot locate the .txt file because you're in the wrong directory. Make sure that where you're trying...
Read more >
Python FileNotFoundError: [Errno 2] No such file or directory ...
The Python FileNotFoundError: [Errno 2] No such file or directory error is often raised by the os library. This error tells you that...
Read more >
OSError: File not found - Odoo
Hi,. In the manifest file inside the data you have specified a file, but in the given path the file is not there....
Read more >
Python giving "file not found" error with both file in same ...
I'm using windows 7, and I have the file in the same directory as the program I'm running. I got this error, so...
Read more >
How do I solve the file not found error in Python? - CodeProject
Either the path is wrong (and "USER" in there does look unlikely) or the file is not where you expected, or not called...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found