Last modified: Apr 07, 2025 By Alexander Williams

How to Install Librosa in Python Step by Step

Librosa is a Python library for audio and music analysis. It helps extract features from audio files. This guide will show you how to install it step by step.

Prerequisites for Installing Librosa

Before installing Librosa, ensure you have Python installed. You can check this by running python --version in your terminal.


python --version

If Python is not installed, download it from the official website. Also, ensure you have pip, Python's package manager.

Step 1: Install Librosa Using Pip

The easiest way to install Librosa is using pip. Open your terminal or command prompt and run the following command.


pip install librosa

This will download and install Librosa along with its dependencies. Wait for the installation to complete.

Step 2: Verify the Installation

After installation, verify Librosa is installed correctly. Open a Python shell and import the library.


import librosa
print(librosa.__version__)

If no errors appear, Librosa is installed correctly. You should see the version number printed.

Step 3: Troubleshooting Common Errors

Sometimes, you may encounter errors like ModuleNotFoundError. This happens if Librosa is not installed properly.

If you see ModuleNotFoundError: No module named 'librosa', reinstall Librosa. Check our guide on how to solve ModuleNotFoundError for more help.

Step 4: Install Optional Dependencies

Librosa works better with some optional dependencies. Install them using pip for full functionality.


pip install numpy scipy matplotlib

These libraries help with numerical operations and visualization. They are often used alongside Librosa.

Step 5: Test Librosa with an Example

Let's test Librosa by loading an audio file. First, download a sample audio file or use your own.


import librosa

# Load audio file
audio_path = 'sample.wav'
y, sr = librosa.load(audio_path)

# Print sample rate and duration
print(f"Sample rate: {sr}")
print(f"Duration: {len(y) / sr} seconds")

This code loads an audio file and prints its sample rate and duration. Ensure the file path is correct.

Conclusion

Installing Librosa in Python is simple with pip. Follow these steps to ensure a smooth setup. If issues arise, refer to our troubleshooting guide.

Now you can start analyzing audio files with Librosa. Explore its features for music and sound processing tasks.