由于不可用,无法使用 Amazon EC2 实例安装 Sndfile

Unable to Install Sndfile with Amazon EC2 Instance due to unavailability

我正在尝试部署一个使用 TensorFlow 和 Librosa 的烧瓶应用程序。因此,作为 Librosa 的依赖项,我需要 sndfile 包。

当我 运行 我的 Flask 应用程序出现此错误时:

import librosa
  File "/home/ec2-user/.local/lib/

python3.7/site-packages/librosa/__init__.py", line 211, in <module>
    from . import core
  File "/home/ec2-user/.local/lib/python3.7/site-packages/librosa/core/__init__.py", line 6, in <module>
    from .audio import *  # pylint: disable=wildcard-import
  File "/home/ec2-user/.local/lib/python3.7/site-packages/librosa/core/audio.py", line 8, in <module>
    import soundfile as sf
  File "/home/ec2-user/.local/lib/python3.7/site-packages/soundfile.py", line 142, in <module>
    raise OSError('sndfile library not found')
OSError: sndfile library not found
[ec2-user@ip-172-31-90-51 CE_Ayush_Deployment]$ python3 app.py
Traceback (most recent call last):
  File "app.py", line 2, in <module>
    from model_pipeline import Corona_Diagnoser
  File "/home/ec2-user/CE_Ayush_Deployment/model_pipeline.py", line 5, in <module>
    import librosa
  File "/home/ec2-user/.local/lib/python3.7/site-packages/librosa/__init__.py", line 211, in <module>
    from . import core
  File "/home/ec2-user/.local/lib/python3.7/site-packages/librosa/core/__init__.py", line 6, in <module>
    from .audio import *  # pylint: disable=wildcard-import
  File "/home/ec2-user/.local/lib/python3.7/site-packages/librosa/core/audio.py", line 8, in <module>
    import soundfile as sf
  File "/home/ec2-user/.local/lib/python3.7/site-packages/soundfile.py", line 142, in <module>
    raise OSError('sndfile library not found')
OSError: sndfile library not found

我试过了:

sudo yum install autoconf autogen automake build-essential libasound2-dev \
   libflac-dev libogg-dev libtool libvorbis-dev libopus-dev libmp3lame-dev \
   libmpg123-dev pkg-config python

然后我收到这条消息:

Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
No package build-essential available.
No package libasound2-dev available.
No package libflac-dev available.
No package libogg-dev available.
No package libvorbis-dev available.
No package libopus-dev available.
No package libmp3lame-dev available.
No package libmpg123-dev available.
No package pkg-config available.

我知道该包在 Amazon EC2 实例中不可用。谁能指导我如何将 sndfile 软件包安装到系统中?

您需要安装 libsndfile 及其开发文件。不幸的是,它没有打包在存储库中,但您可以通过直接下载 RPM 来安装它

wget http://ftp.altlinux.org/pub/distributions/ALTLinux/Sisyphus/x86_64/RPMS.classic//libsndfile-1.0.31-alt1.x86_64.rpm
wget http://ftp.altlinux.org/pub/distributions/ALTLinux/Sisyphus/x86_64/RPMS.classic//libsndfile-devel-1.0.28-alt1.x86_64.rpm

sudo yum localinstall libsndfile-devel-1.0.31-alt1.x86_64.rpm

您还可以从源安装 libsndfile

另一种选择是切换到 Ubuntu,其中包含 libsndfilelibsndfile-dev 的软件包。如果您希望专门部署 tensorflow,那么您应该从 AWS Deep Learning AMI 开始。这些 AMI 由 AWS 构建,并附带驱动程序和一系列已安装的框架。这些 AMis 有 Ubuntu 个风味版本。

亚马逊 Linux 2

我在 Amazon Linux 2,您可以通过 运行 在您的 EC2 服务器上进行以下验证。

[ec2-user@fake-ip ~]$ cat /etc/system-release
Amazon Linux release 2 (Karoo)

Amazon package repository 提供以下软件包:libsndfile-devellibsndfile-utilslibsndfile

 [ec2-user@fakeip ~]$ yum search libsndfile
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
=============================================== N/S matched: libsndfile ================================================
libsndfile-devel.x86_64 : Development files for libsndfile
libsndfile-utils.x86_64 : Command Line Utilities for libsndfile
libsndfile.x86_64 : Library for reading and writing sound files
libsndfile.i686 : Library for reading and writing sound files

亚马逊 Linux AMI

根据 Amazon Linux AMI package list,此早期版本的亚马逊 Linux 没有 libsndfile。尽管您可以为企业启用额外包 Linux (EPEL),但 libsndfile 似乎也不存在。

[ec2-user@fakeip ~]$ cat /etc/system-release
Amazon Linux AMI release 2018.03
[ec2-user@fakeip ~]$ sudo yum-config-manager --enable epel
... skipping lots of output
mirrorlist = https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=x86_64
...
[ec2-user@fakeip ~]$ yum search libsndfile
Loaded plugins: priorities, update-motd, upgrade-helper
epel/x86_64/metalink                         | 3.8 kB  00:00:00
epel                                         | 4.7 kB  00:00:00
(1/3): epel/x86_64/group_gz                  |  74 kB  00:00:00
(2/3): epel/x86_64/updateinfo                | 788 kB  00:00:00
(3/3): epel/x86_64/primary_db                | 6.1 MB  00:00:00
1067 packages excluded due to repository priority protections
Warning: No matches found for: libsndfile
No matches found

libsndfile docs声明它已经在Debian/GNULinux上编译,但是亚马逊Linux AMI不是基于在 Debian 上。 libsndfile 的构建依赖项 (autoconf autogen automake build-essential libasound2-dev libflac-dev libogg-dev libtool libvorbis-dev libopus-dev libmp3lame-dev libmpg123-dev pkg-config python) 都指的是 Debian 软件包,其他 Linux 风格的软件包名称不同。特别是,build-essentiallibasound2-devlibflac-devlibopus-devlibmp3lame-devlibmpg123-dev 不在 EPEL 上。

[ec2-user@fakeip ~]$ yum search autoconf autogen automake build-essential \
    libasound2-dev   libflac-dev libogg-dev libtool libvorbis-dev libopus-dev \
    libmp3lame-dev   libmpg123-dev pkg-config python
... skipping output
Warning: No matches found for: build-essential
Warning: No matches found for: libasound2-dev
Warning: No matches found for: libflac-dev
Warning: No matches found for: libopus-dev
Warning: No matches found for: libmp3lame-dev
Warning: No matches found for: libmpg123-dev

libmpelame-dev 可能是 lame-devel, lame-libs, lame, and/or lame-mp3x.

[ec2-user@fakeip ~]$ yum search lame
Loaded plugins: priorities, update-motd, upgrade-helper
1067 packages excluded due to repository priority protections
================================================== N/S matched: lame ===================================================
lame-devel.i686 : Development files for lame
lame-devel.x86_64 : Development files for lame
lame-libs.i686 : LAME MP3 encoding library
lame-libs.x86_64 : LAME MP3 encoding library
flamerobin.x86_64 : Graphical client for Firebird
lame.x86_64 : Free MP3 audio compressor
lame-mp3x.x86_64 : MP3 frame analyzer

libflac-dev 可能是 flac-devel

[ec2-user@fakeip ~]$ yum search flac
Loaded plugins: priorities, update-motd, upgrade-helper
1067 packages excluded due to repository priority protections
================================================== N/S matched: flac ===================================================
flac-devel.x86_64 : Development libraries and header files from FLAC
easytag.x86_64 : Tag editor for mp3, ogg, flac and other music files
flac.i686 : An encoder/decoder for the Free Lossless Audio Codec
flac.x86_64 : An encoder/decoder for the Free Lossless Audio Codec
mp3fs.x86_64 : FUSE filesystem to transcode FLAC to MP3 on the fly

libopus-dev 可能是 opus-devel

[ec2-user@fakeip ~]$ yum search opus
Loaded plugins: priorities, update-motd, upgrade-helper
1067 packages excluded due to repository priority protections
================================================== N/S matched: opus ===================================================
opus-devel.i686 : Development package for opus
opus-devel.x86_64 : Development package for opus
opus.i686 : An audio codec for use in low-delay speech and audio communication
opus.x86_64 : An audio codec for use in low-delay speech and audio communication

libmpg123-devhttps://www.mpg123.org/

建议

  • 将您的 EC2 切换到 Amazon Linux 2 或 Ubuntu
  • 运行 您的应用在 EC2 上的 Docker 映像中