파이썬 librosa 설치 - paisseon librosa seolchi

파이썬 librosa 설치 - paisseon librosa seolchi
Librosa 설치 오류 및 soundfile library not found Error

librosa 설치 오류

Librosa를 처음 설치하다 보면, 아래와 같이 import도 되지 않는 상황이 종종 발생하곤 한다.

아무리, pip 명령어를 만져봐도 시작부터 되지 않는 경우이다. 

sndfile library not found

librosa는 내부적으로, scipy.wavefile과 sounfile 라이브러리를 사용하는데, soundfile 라이브러리 설치가 잘 안되서 발생하는 문제이다. soundfile library는 파이썬 외에 os차원에서 설치해야하는 library가 포함되어 있기 때문에, pip 및 종속성검사로 설치가 되지 않는다. 

파이썬 librosa 설치 - paisseon librosa seolchi
"sndfile library not found"에러가 뜨면서 librosa가 import도 되지 않는다.

Librosa 공식웹페이지 이외, Github Page를 참조하면, Soundfile을 설치할 때 다음과 같은 사전설치/업데이트가 필요하다고 가이드 되어 있다. (놓치기 쉽다. 그냥 `pip install librosa` 하기 때문)

apt-get install ffmpeg   # Linux

또는,

apt-get install gstreamer1.0-plugins-base gstreamer1.0-plugins-ugly

MacOS의 경우

brew install ffmpeg
   혹은
brew install gstreamer

Conda를 사용하는 경우,

conda install -c conda-forge ffmpeg
conda install -c conda-forge librosa
conda 가 지원하는 환경이라면, conda 최고~~~!!!

그런데, 이렇게 해 주어도 안되는 경우가 있다. 그렇다면 아래와 같이 해 주자. 

soundfile library를 다시 설치 해 주자.

sudo apt-get update
sudo apt-get install -y libsndfile1-dev

간혹 설치 완료 후에도 여전히 에러가 발생하는 경우가 있는 Notebook을 재시작 해주면 해결 된다. ^^;

2018년 9월 20일 Python librosa, mac, pip, Python, Ubuntu

사용법

음원 분석에 사용하는 라이브러리인 librosa를 설치하는 방법을 정리해둔다.

설치방법: Mac

$ pip install librosa
$ brew install ffmpeg

설치방법: Ubuntu

$ pip install librosa
$ sudo apt-get install -y ffmpeg

관련

파이썬 librosa 설치 - paisseon librosa seolchi

Table of Contents #

  1. Install librosa on Windows
  2. Install librosa on macOS or Linux
  3. Install librosa in Visual Studio Code
  4. Install librosa in PyCharm
  5. Install librosa in Anaconda
  6. Install librosa in Jupyter Notebook

Install librosa on Windows #

To install the librosa module on Windows:

  1. Type CMD in the search bar and open the Command Prompt application.
  2. Type pip install librosa and press Enter.

Copied!

pip install librosa # 👇️ for Python 3 pip3 install librosa # 👇️ if you don't have pip in your PATH environment variable python -m pip install librosa # 👇️ for Python 3 python3 -m pip install librosa # 👇️ using py alias py -m pip install librosa # 👇️ if you get permissions error pip install librosa --user # 👇️ for Anaconda conda install -c conda-forge librosa

파이썬 librosa 설치 - paisseon librosa seolchi

If the command doesn't succeed, try running CMD as an administrator.

Right-click on the search result, click on "Run as administrator" and run the pip install command.

파이썬 librosa 설치 - paisseon librosa seolchi

If you get the error "ModuleNotFoundError: No module named 'librosa' in Python", check out my other article:

  • ModuleNotFoundError: No module named 'librosa' in Python

If you get the error "'pip' is not recognized as an internal or external command", use the python -m command when installing librosa.

Copied!

python -m pip install librosa python3 -m pip install librosa py -m pip install librosa

Alternatively, you can install the librosa module in a virtual environment:

  1. Open the root directory of your project.
  2. Press Shift and right-click in Explorer.

파이썬 librosa 설치 - paisseon librosa seolchi

  1. Click on "Open PowerShell window here".
  2. Run the following commands.

Copied!

# 👇️ might also be: "python3 -m venv venv" python -m venv venv # 👇️ activate on Windows (PowerShell) venv\Scripts\Activate.ps1 # 👇️ activate on Windows (cmd.exe) venv\Scripts\activate.bat # 👇️ install librosa in virtual environment pip install librosa

If the python -m venv venv command doesn't work, try the following 2 commands:

  • python3 -m venv venv
  • py -m venv venv.

If you see an error message that "ps1 cannot be loaded because running scripts is disabled on this system", run the following command, type "yes" when prompted and rerun the activation command.

Copied!

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

You can verify that the librosa module is installed by using the pip show librosa command.

Copied!

pip show librosa pip3 show librosa python -m pip show librosa python3 -m pip show librosa

The pip show librosa command will either state that the package is not installed or show a bunch of information about the package, including the location where the package is installed.

Install librosa on macOS or Linux #

To install librosa on macOS or Linux:

  1. Search for "terminal" and start the application.
  2. Type pip install librosa and press Enter.

파이썬 librosa 설치 - paisseon librosa seolchi

Copied!

pip install librosa # 👇️ for Python 3 pip3 install librosa # 👇️ if you get permissions error sudo pip3 install librosa # 👇️ if you don't have pip in your PATH environment variable python -m pip install librosa # 👇️ for python 3 python3 -m pip install librosa # 👇️ alternative if you get permissions error pip install librosa --user # 👇️ for Anaconda conda install -c conda-forge librosa

파이썬 librosa 설치 - paisseon librosa seolchi

If you get an error that pip isn't found, use the python -m command.

Copied!

python -m pip install librosa python3 -m pip install librosa

If you get a permissions error, prefix the command with sudo.

Copied!

sudo pip install librosa sudo pip3 install librosa

Alternatively, you can install the librosa package in a virtual environment:

  1. Open your terminal in the root directory of your project.
  2. Run the following commands.

Copied!

# 👇️ could also be "python -m venv venv" python3 -m venv venv # 👇️ activate virtual env on macOS or Linux source venv/bin/activate # 👇️ install librosa in virtual environment pip install librosa

Your virtual environment will use the version of Python that was used to create it.

If the python3 -m venv venv command doesn't work, use python -m venv venv instead.

If you get the error "ModuleNotFoundError: No module named 'librosa' in Python", check out my other article:

  • ModuleNotFoundError: No module named 'librosa' in Python

You can use the pip show command to verify librosa has been installed successfully.

Copied!

pip show librosa pip3 show librosa python -m pip show librosa python3 -m pip show librosa

The pip show librosa command will either state that the package is not installed or show a bunch of information about the package.

Install librosa in Visual Studio Code #

To install librosa in Visual Studio Code:

  1. Press CTRL + ` (Backtick) on your keyboard to open the terminal.
  2. Run the pip install librosa command to install the librosa module.

Copied!

pip install librosa # 👇️ for Python 3 pip3 install librosa # 👇️ if you get permissions error sudo pip3 install librosa # 👇️ if you don't have pip in your PATH environment variable python -m pip install librosa # 👇️ for python 3 python3 -m pip install librosa # 👇️ using py alias py -m pip install librosa # 👇️ alternative if you get permissions error pip install librosa --user

파이썬 librosa 설치 - paisseon librosa seolchi

You can also open the terminal in Visual studio code by pressing CTRL+Shift+P and then typing "View: Toggle Terminal".

When installing Python modules in Visual Studio code, make sure that your IDE is configured to use the correct version of Python.

Press CTRL+Shift+P or ( + Shift + P on Mac) to open the command palette.

Then type "Python select interpreter" in the field.

파이썬 librosa 설치 - paisseon librosa seolchi

Then select the correct Python version from the dropdown menu.

파이썬 librosa 설치 - paisseon librosa seolchi

Your IDE should be using the same version of Python (including the virtual environment) that you are using to install packages from your terminal.

You can use the python --version command if you need to get your version of Python.

Copied!

python --version python3 --version

파이썬 librosa 설치 - paisseon librosa seolchi

You can also try creating a virtual environment if you don't already have one.

Copied!

# 👇️ could also be "python -m venv venv" or "py -m venv venv" python3 -m venv venv # 👇️ activate on Unix or MacOS source venv/bin/activate # 👇️ activate on Windows (cmd.exe) venv\Scripts\activate.bat # 👇️ activate on Windows (PowerShell) venv\Scripts\Activate.ps1 # 👇️ install librosa in virtual environment pip install librosa

Your virtual environment will use the version of Python that was used to create it.

If you get the error "ModuleNotFoundError: No module named 'librosa' in Python", check out my other article:

  • ModuleNotFoundError: No module named 'librosa' in Python

Install librosa in PyCharm #

To install librosa in PyCharm:

  1. Press Alt+F12 on your keyboard to open the terminal.
  2. Run the pip install librosa command to install the librosa module.

Copied!

pip install librosa # 👇️ for Python 3 pip3 install librosa # 👇️ if you get permissions error sudo pip3 install librosa # 👇️ if you don't have pip in your PATH environment variable python -m pip install librosa # 👇️ for python 3 python3 -m pip install librosa # 👇️ using py alias py -m pip install librosa # 👇️ alternative if you get permissions error pip install librosa --user

파이썬 librosa 설치 - paisseon librosa seolchi

Alternatively, you can use the IDE itself to install the module.

To install librosa in PyCharm:

  1. Click on "File" > "Settings" > "Project" > "Python Interpreter".
  2. Click on the + icon and type librosa.
  3. Click on "Install Package".

파이썬 librosa 설치 - paisseon librosa seolchi

When installing Python modules in PyCharm, make sure that your IDE is configured to use the correct version of Python.

Click on "File" > "Settings" > "Project" > "Python Interpreter".

파이썬 librosa 설치 - paisseon librosa seolchi

Then select the correct Python version from the dropdown menu.

Your IDE should be using the same version of Python (including the virtual environment) that you are using to install packages from your terminal.

You can use the python --version command if you need to get your version of Python.

Copied!

python --version python3 --version

파이썬 librosa 설치 - paisseon librosa seolchi

Install librosa in Anaconda #

You can install the librosa package with a command.

If you are on Windows, search for "Anaconda Prompt" and open the application.

If you are on macOS or Linux, open your terminal.

Run the following command to install the librosa package.

Copied!

# 👇️ using conda conda install -c conda-forge librosa # 👇️ Alternatively use `pip` pip install librosa # 👇️ for Python 3 pip3 install librosa # 👇️ if you get permissions error sudo pip3 install librosa # 👇️ if you don't have pip in your PATH environment variable python -m pip install librosa # 👇️ for python 3 python3 -m pip install librosa # 👇️ using py alias py -m pip install librosa # 👇️ alternative if you get permissions error pip install librosa --user

If you get the error "ModuleNotFoundError: No module named 'librosa' in Python", check out my other article:

  • ModuleNotFoundError: No module named 'librosa' in Python

Install librosa in Jupyter Notebook #

To install librosa in Jupyter Notebook:

  1. Open your terminal and type "jupyter notebook".

파이썬 librosa 설치 - paisseon librosa seolchi

  1. Click on "New" and then "Terminal" in the browser tab.

파이썬 librosa 설치 - paisseon librosa seolchi

  1. Type pip install librosa and press Enter.

Copied!

# 👇️ using pip pip install librosa # 👇️ for Python 3 pip3 install librosa # 👇️ if you get permissions error sudo pip3 install librosa # 👇️ if you don't have pip in your PATH environment variable python -m pip install librosa # 👇️ for python 3 python3 -m pip install librosa # 👇️ using py alias py -m pip install librosa # 👇️ using conda conda install -c conda-forge librosa # 👇️ alternative if you get permissions error pip install librosa --user

Alternatively, you can use the Python ipykernel.

To install librosa in Jupyter Notebook:

  1. Open your terminal and type "jupyter notebook".

파이썬 librosa 설치 - paisseon librosa seolchi

  1. Click on "New" and then click on "Python 3 (ipykernel)".

    파이썬 librosa 설치 - paisseon librosa seolchi

  2. Type !pip install librosa and click on "Run".

파이썬 librosa 설치 - paisseon librosa seolchi

Note that the pip install command must be prefixed with an exclamation mark if you use this approach.

Copied!

!pip install librosa

Once you type the command, click "Run" to install the librosa module.

If you get a permissions error, e.g. "[WinError: 5] Access is denied", add the --user option to the installation command.

Copied!

!pip install librosa --user

파이썬 librosa 설치 - paisseon librosa seolchi