在docker中:OSError:ctypes.util.find_library()未能找到名为'sndfile'的库

时间:2019-07-10 16:08:28

标签: docker libsndfile

我在Windows 10 Pro计算机上使用Docker(Linux容器)。我创建了一个docker容器来运行我的flask应用程序,并在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.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'

1 个答案:

答案 0 :(得分:1)

我做了一个快速测试。看来您缺少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命令中。这是最佳实践检查this

希望这会有所帮助。