Lakshya Kumar
Lakshya Kumar

Reputation: 65

partially initialized module 'librosa' has no attribute 'example' (most likely due to a circular import)

I'm trying to run a simple librosa code. I installed librosa using pip3. I'm using Python 3.8.5 on Linux.

Error:

Traceback (most recent call last):
  File "librosa.py", line 1, in <module>
    import librosa
  File "/home/k/Desktop/speechanalysy/librosa.py", line 4, in <module>
    filename = librosa.example('323-1147')
AttributeError: partially initialized module 'librosa' has no attribute 'example' (most likely due to a circular import)

Code:

import librosa

filename = librosa.example('323-1147')
y, sr = librosa.load(filename)
tempo, beat_frames = librosa.beat.beat_track(y=y, sr=sr)

Upvotes: 0

Views: 2643

Answers (1)

Jon Nordby
Jon Nordby

Reputation: 6269

Your file is called "librosa.py". So when you do "import librosa" from that file, is likely to match that file - a circular import. The solution is to rename your file to something else, like "beattracker.py" - so that the import will resolve to the real librosa library.

Upvotes: 2

Related Questions