docker - 在 docker 中:OSError: ctypes.util.find_library() 无法找到名为“sndfile”的库
问题描述
我在 Windows 10 Pro 机器上使用 Docker(Linux 容器)。我创建了一个 docker 容器来运行我的烧瓶应用程序,并在 requirements.txt 文件中提到了所需的库。
当我运行 docker 容器时,我收到以下消息
OSError: ctypes.util.find_library() 未能找到名为“sndfile”的库。
如何在 Docker 中安装 sndfile 库?
参考链接:https : //pysoundfile.readthedocs.io/en/0.9.0/ 我尝试在 Dockerfile 中使用以下命令安装 libsndfile
---- RUN apt-get install libsndfile1
Got Below message from docker build:
Step 5/7 : RUN apt-get install libsndfile1
---> Running in <container>
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package libsndfile1
The command '/bin/sh -c apt-get install libsndfile1' returned a non-zero code: 100
1.码头版:
Client:
Version: 17.03.1-ce-rc1
API version: 1.27
Go version: go1.7.5
Git commit: 3476dbf
Built: Wed Mar 15 20:33:22 2017
OS/Arch: windows/amd64
Server:
Version: 17.03.1-ce-rc1
API version: 1.27 (minimum version 1.12)
Go version: go1.7.5
Git commit: 3476dbf
Built: Wed Mar 15 20:28:18 2017
OS/Arch: linux/amd64
Experimental: true
2.requirements.txt文件
flask
tensorflow-gpu
flask_cors
uuid
librosa
pysoundfile
numpy
cffi
requests
wave
h5py
pydub
werkzeug
完整的错误信息:
File "app.py", line 5, in <module>
import librosa
File "/usr/local/lib/python3.7/site-packages/librosa/__init__.py", line 13, in <module>
from . import core
File "/usr/local/lib/python3.7/site-packages/librosa/core/__init__.py", line 115, in <module>
from .audio import * # pylint: disable=wildcard-import
File "/usr/local/lib/python3.7/site-packages/librosa/core/audio.py", line 8, in <module>
import soundfile as sf
File "/usr/local/lib/python3.7/site-packages/soundfile.py", line 267, in <module>
_snd = _ffi.dlopen('sndfile')
File "/usr/local/lib/python3.7/site-packages/cffi/api.py", line 146, in dlopen
lib, function_cache = _make_ffi_library(self, name, flags)
File "/usr/local/lib/python3.7/site-packages/cffi/api.py", line 828, in _make_ffi_library
backendlib = _load_backend_lib(backend, libname, flags)
File "/usr/local/lib/python3.7/site-packages/cffi/api.py", line 823, in _load_backend_lib
raise OSError(msg)
OSError: ctypes.util.find_library() did not manage to locate a library called 'sndfile'
解决方案
我做了一个快速测试。看来您缺少apt-get -y update
命令。
尝试RUN apt-get -y update
在该RUN apt-get install libsndfile1
行之前添加。
这是我尝试过的,它奏效了。
$ cat Dockerfile
FROM ubuntu
RUN apt-get -y update
RUN apt-get install -y libsndfile1
CMD /bin/bash
$
$
$ docker build -t t:t .
Sending build context to Docker daemon 1.748MB
Step 1/4 : FROM ubuntu
---> 4c108a37151f
Step 2/4 : RUN apt-get -y update
---> Using cache
---> 55bfc92d838b
Step 3/4 : RUN apt-get install -y libsndfile1
---> Running in d5722e1f85f1
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
libflac8 libogg0 libvorbis0a libvorbisenc2 multiarch-support
The following NEW packages will be installed:
libflac8 libogg0 libsndfile1 libvorbis0a libvorbisenc2 multiarch-support
0 upgraded, 6 newly installed, 0 to remove and 8 not upgraded.
Need to get 564 kB of archives.
After this operation, 2300 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu bionic/main amd64 multiarch-support amd64 2.27-3ubuntu1 [6916 B]
Get:2 http://archive.ubuntu.com/ubuntu bionic/main amd64 libogg0 amd64 1.3.2-1 [17.2 kB]
Get:3 http://archive.ubuntu.com/ubuntu bionic/main amd64 libflac8 amd64 1.3.2-1 [213 kB]
Get:4 http://archive.ubuntu.com/ubuntu bionic/main amd64 libvorbis0a amd64 1.3.5-4.2 [86.4 kB]
Get:5 http://archive.ubuntu.com/ubuntu bionic/main amd64 libvorbisenc2 amd64 1.3.5-4.2 [70.7 kB]
Get:6 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libsndfile1 amd64 1.0.28-4ubuntu0.18.04.1 [170 kB]
debconf: delaying package configuration, since apt-utils is not installed
Fetched 564 kB in 1s (925 kB/s)
Selecting previously unselected package multiarch-support.
(Reading database ... 4040 files and directories currently installed.)
Preparing to unpack .../multiarch-support_2.27-3ubuntu1_amd64.deb ...
Unpacking multiarch-support (2.27-3ubuntu1) ...
Setting up multiarch-support (2.27-3ubuntu1) ...
Selecting previously unselected package libogg0:amd64.
(Reading database ... 4043 files and directories currently installed.)
Preparing to unpack .../libogg0_1.3.2-1_amd64.deb ...
Unpacking libogg0:amd64 (1.3.2-1) ...
Selecting previously unselected package libflac8:amd64.
Preparing to unpack .../libflac8_1.3.2-1_amd64.deb ...
Unpacking libflac8:amd64 (1.3.2-1) ...
Selecting previously unselected package libvorbis0a:amd64.
Preparing to unpack .../libvorbis0a_1.3.5-4.2_amd64.deb ...
Unpacking libvorbis0a:amd64 (1.3.5-4.2) ...
Selecting previously unselected package libvorbisenc2:amd64.
Preparing to unpack .../libvorbisenc2_1.3.5-4.2_amd64.deb ...
Unpacking libvorbisenc2:amd64 (1.3.5-4.2) ...
Selecting previously unselected package libsndfile1:amd64.
Preparing to unpack .../libsndfile1_1.0.28-4ubuntu0.18.04.1_amd64.deb ...
Unpacking libsndfile1:amd64 (1.0.28-4ubuntu0.18.04.1) ...
Setting up libogg0:amd64 (1.3.2-1) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Setting up libvorbis0a:amd64 (1.3.5-4.2) ...
Setting up libflac8:amd64 (1.3.2-1) ...
Setting up libvorbisenc2:amd64 (1.3.5-4.2) ...
Setting up libsndfile1:amd64 (1.0.28-4ubuntu0.18.04.1) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Removing intermediate container d5722e1f85f1
---> 983dbe47e769
Step 4/4 : CMD /bin/bash
---> Running in 286008c87197
Removing intermediate container 286008c87197
---> b302a2c7c958
Successfully built b302a2c7c958
Successfully tagged t:t
$
此外,如果可能,请尝试apt-get -y update && apt-get install -y libsndfile1
在 Dockerfile 中放入单个 RUN 命令。这是最好的做法检查这个。
希望这可以帮助。
推荐阅读
- electron - 如何在电子原子的两个扩展监视器的总中心打开 newBrowserWindow
- user-interface - 当数组中元素的值发生变化时,React-Native 更新 UI,而不使用 ForceUpdate
- python - 如果列中的值匹配,则合并熊猫数据框中的计数和行
- html - 在html电子邮件中对齐表格中的数据单元格元素
- svg - CSS 类不适用于 svg 元素
- angular - Angular 2 4 5 - 如何在重新加载页面或单击 Angular 的“返回”按钮时保存搜索结果
- python - Python:以数字方式对列表列表进行排序
- teradata - Teradata 过去 6 个月的总计
- python - Discord Python Bot:清除命令 If 语句
- prolog - 使序言谓词具有确定性