Librosa raised OSError(sndfile library not found) in Docker

2024/12/9 21:47:35

I'm trying to write the Dockerfile for a small python web project and there is something wrong with the dependencies. I've been doing some search on the internet and it said that Librosa library requires libsndfile to work properly so I tried to install it using apt-get install libsndfile1 (I've also tried libsndfile-dev,...) . However, it doesn't seem to solve my problem.

This is how my Dockerfile looks like:

FROM python:3.6-buster as buildENV STATIC_URL /static
ENV STATIC_PATH /var/www/app/staticWORKDIR /var/www/RUN python -m venv /opt/venvENV PATH="/opt/venv/bin:$PATH"COPY requirements.txt .RUN pip install -r requirements.txtRUN pip install gunicornRUN apt-get update -y && apt-get install -y --no-install-recommends build-essential gcc \libsndfile1 FROM python:3.6-buster AS runCOPY --from=build /opt/venv /opt/venvCOPY . .ENV PATH="/opt/venv/bin:$PATH"RUN gunicorn -b :5000 --access-logfile - --error-logfile - app:app

However, when i try to build and run this, this error occured:

[2020-04-15 17:30:02 +0000] [7] [INFO] Starting gunicorn 20.0.4
[2020-04-15 17:30:02 +0000] [7] [INFO] Listening at: http://0.0.0.0:5000 (7)
[2020-04-15 17:30:02 +0000] [7] [INFO] Using worker: sync
[2020-04-15 17:30:02 +0000] [10] [INFO] Booting worker with pid: 10
[2020-04-15 17:30:03 +0000] [10] [ERROR] Exception in worker process
Traceback (most recent call last):File "/opt/venv/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_workerworker.init_process()File "/opt/venv/lib/python3.6/site-packages/gunicorn/workers/base.py", line 119, in init_processself.load_wsgi()File "/opt/venv/lib/python3.6/site-packages/gunicorn/workers/base.py", line 144, in load_wsgiself.wsgi = self.app.wsgi()File "/opt/venv/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgiself.callable = self.load()File "/opt/venv/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 49, in loadreturn self.load_wsgiapp()File "/opt/venv/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiappreturn util.import_app(self.app_uri)File "/opt/venv/lib/python3.6/site-packages/gunicorn/util.py", line 358, in import_appmod = importlib.import_module(module)File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_modulereturn _bootstrap._gcd_import(name[level:], package, level)File "<frozen importlib._bootstrap>", line 994, in _gcd_importFile "<frozen importlib._bootstrap>", line 971, in _find_and_loadFile "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlockedFile "<frozen importlib._bootstrap>", line 665, in _load_unlockedFile "<frozen importlib._bootstrap_external>", line 678, in exec_moduleFile "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removedFile "/app.py", line 12, in <module>from emotion_model.test import load_model, inference_segmentFile "/emotion_model/test.py", line 9, in <module>import librosaFile "/opt/venv/lib/python3.6/site-packages/librosa/__init__.py", line 12, in <module>from . import coreFile "/opt/venv/lib/python3.6/site-packages/librosa/core/__init__.py", line 126, in <module>from .audio import *  # pylint: disable=wildcard-importFile "/opt/venv/lib/python3.6/site-packages/librosa/core/audio.py", line 10, in <module>import soundfile as sfFile "/opt/venv/lib/python3.6/site-packages/soundfile.py", line 142, in <module>raise OSError('sndfile library not found')
OSError: sndfile library not found
[2020-04-15 17:30:03 +0000] [10] [INFO] Worker exiting (pid: 10)
[2020-04-15 17:30:03 +0000] [7] [INFO] Shutting down: Master
[2020-04-15 17:30:03 +0000] [7] [INFO] Reason: Worker failed to boot.
Answer

For those who come to this post to find a solution. My workaround was to put the installation of libsndfile after this part:

FROM python:3.6-buster AS runCOPY --from=build /opt/venv /opt/venvCOPY . .ENV PATH="/opt/venv/bin:$PATH"

which would be:

FROM python:3.6-buster AS runCOPY --from=build /opt/venv /opt/venvCOPY . .ENV PATH="/opt/venv/bin:$PATH"RUN apt-get update -y && apt-get install -y --no-install-recommends build-essential gcc \libsndfile1 RUN gunicorn -b :5000 --access-logfile - --error-logfile - app:app
https://en.xdnf.cn/q/73206.html

Related Q&A

Implementing Tags using Django rest framework

TDLR : what is the best way to implement tags in django-rest-framework. where the tags has a created_by field which is the currently authenticated user.I am trying to achieve a very simple/common thing…

Python audiolab install, unable to install (or find) libsndfile on Mac OSX

Trying to install scikits.audiolab-0.11.0 on Mac, bit it requires libsndfile: http://www.mega-nerd.com/libsndfile/. I did install libsndfile supposedly, using libsndfile_python-1.0.0-py2.7-macosx10.5.m…

Connecting to events of another widget

This is most likely a duplicate question, but I have to ask it because other answers arent helping in my case, since I am new to pyqt (switched from tkinter few days ago).I am wondering if is it possib…

Diff multidimensional dictionaries in python

I have two dictionariesa = {home: {name: Team1, score: 0}, away: {name: Team2, score: 0}} b = {home: {name: Team1, score: 2}, away: {name: Team2, score: 0}}The keys never change but I want to get that …

Pandas DatetimeIndex vs to_datetime discrepancies

Im trying to convert a Pandas Series of epoch timestamps to human-readable times. There are at least two obvious ways to do this: pd.DatetimeIndex and pd.to_datetime(). They seem to work in quite dif…

Slicing a circle in equal segments, Python

I have a set of close of 10,000 points on the sky. They are plotted using the RA (right ascension) and DEC (declination) on the sky. When plotted, they take the shape of a circle. What I would like to …

Pyautogui screenshot. Where does it go? How to save and find later?

I am learning from Al Sweigarts you tube video for automating the boring stuff. I got to the part of taking screenshots. He didnt really explain in his video so I tested things out. I found that it tak…

How to get pip to point to newer version of Python

I have two versions of Python installed on my centOS server. [ethan@demo ~]$ python2.6 --version Python 2.6.6 [ehtan@demo ~]$ python --version Python 2.7.3The older version (2.6) is required by some es…

Connect JS client with Python server

Im relatively new to JS and Python, so this is probably a beginners question. Im trying to send a string from a JS client to Python Server (and then send the string to another Python client).This is my…

Pip does not acknowledge Cython

I just installed pip and Python via home-brew on a fresh Mac OS installation.First of all, my pip is not installing dependencies at all - which forces me to re-run pip install tables 3 times and every …