In docker : OSError: ctypes.util.find_library() did not manage to locate a library called 'sndfile'

In docker : OSError: ctypes.util.find_library() did not manage to locate a library called 'sndfile'

我在 Windows 10 Pro 上使用 Docker(Linux 容器) machine.I 为 运行 我的烧瓶创建了一个 docker 容器应用程序并在 requirements.txt 文件中提到了所需的库。

当我 运行 docker 容器时,我收到以下消息

OSError: ctypes.util.find_library() 未能找到名为 'sndfile'.

的库

如何在 Docker 中安装 sndfile 库?

参考link: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.DOCKER 版本:

    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 install libsndfile1 行之前添加 RUN apt-get -y update

这是我尝试过的并且有效。

$ 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 中的单个 运行 命令中。这是最佳实践检查 this.

希望这对您有所帮助。