Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scikits.audiolab on Ubuntu Oneiric - ImportError: No module named _sndfile

Tags:

python

Okay, so I wanted to do some basic signal processing in Python and found this great library called scikits.audiolab.

No PPA anywhere to be found. Oh well. I thought I could install it on my Ubuntu Oneiric server by simply

sudo aptitude install libsndfile-dev

and then

sudo easy_install scikits.audiolab

This, however, failed with

error: sndfile (http://www.mega-nerd.com/libsndfile/) library not found.
Directories to search for the libraries can be specified in the
site.cfg file, in section [sndfile].

Wtf? Okay, queried the libsndfile1-dev file list:

japsu@helios ~ $ apt-file list libsndfile1-dev
libsndfile1-dev: /usr/include/sndfile.h
libsndfile1-dev: /usr/include/sndfile.hh
libsndfile1-dev: /usr/lib/x86_64-linux-gnu/libsndfile.a
libsndfile1-dev: /usr/lib/x86_64-linux-gnu/libsndfile.la
libsndfile1-dev: /usr/lib/x86_64-linux-gnu/libsndfile.so
libsndfile1-dev: /usr/lib/x86_64-linux-gnu/pkgconfig/sndfile.pc
[...]

Weird, libraries going into non-standard library directory? Stupid packager.

Oh well. Downloaded the source for scikits.audiolab, wrote a site.cfg like this:

[sndfile]
include_dirs = /usr/include
library_dirs = /usr/lib/x86_64-linux-gnu/
sndfile_libs = sndfile

Now python setup.py build and sudo setup.py install completed successfully.

Next, fired up a Python shell, tried to from scikits.audiolab import sndfile:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "scikits/audiolab/__init__.py", line 25, in <module>
    from pysndfile import formatinfo, sndfile
  File "scikits/audiolab/pysndfile/__init__.py", line 1, in <module>
    from _sndfile import Sndfile, Format, available_file_formats, \
ImportError: No module named _sndfile

But:

>> sys.path
['',
 '/usr/bin',
 '/usr/lib/pymodules/python2.7',
 '/usr/local/lib/python2.7/dist-packages/scikits.audiolab-0.11.0-py2.7-linux-x86_64.egg',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-linux2',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/IPython/Extensions',
 u'/home/japsu/.ipython']

And _sndfile.so found at /usr/local/lib/python2.7/dist-packages/scikits.audiolab-0.11.0-py2.7-linux-x86_64.egg/scikits/audiolab/pysndfile/_sndfile.so.

So, my question is,

  1. Wtf is going on? Why doesn't python find _sndfile.so?
  2. Has anyone successfully used scikits.audiolab in 2011 on a 2011 Linux distro? How did you do it?
  3. Are there any good alternative libraries for reading HUGE (like, 10 GB / 8 hours) WAV files chunk by chunk into NumPy?
like image 761
Santtu Pajukanta Avatar asked Dec 11 '11 00:12

Santtu Pajukanta


1 Answers

Someone suggested I check ldd _sndfile.so. Did just that and got

    linux-vdso.so.1 =>  (0x00007fffd3dea000)
    libsndfile.so.1 => /usr/lib/x86_64-linux-gnu/libsndfile.so.1 (0x00007f2bfbb5b000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f2bfb93e000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2bfb59e000)
    libFLAC.so.8 => /usr/lib/x86_64-linux-gnu/libFLAC.so.8 (0x00007f2bfb354000)
    libvorbisenc.so.2 => /usr/lib/x86_64-linux-gnu/libvorbisenc.so.2 (0x00007f2bfae85000)
    libvorbis.so.0 => /usr/lib/x86_64-linux-gnu/libvorbis.so.0 (0x00007f2bfac58000)
    libogg.so.0 => /usr/lib/x86_64-linux-gnu/libogg.so.0 (0x00007f2bfaa51000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f2bfa7cd000)

Interesting! A bunch of file format libraries are also referenced, ones that I probably do not have installed.

Did sudo aptitude install flac vorbis-tools and voila!

In [1]: from scikits.audiolab import sndfile
/usr/local/lib/python2.7/dist-packages/scikits.audiolab-0.11.0-py2.7-linux-x86_6                                     
4.egg/scikits/audiolab/soundio/play.py:48: UserWarning: Could not import alsa ba                                     
ckend; most probably, you did not have alsa headers when building audiolab
warnings.warn("Could not import alsa backend; most probably, "

I can probably ignore that warning about missing ALSA support for now as it's probably used for local recording and playback - and this is a server anyway.

It would have been a whole lot easier if the lack of libFLAC, libvorbis and libvorbisenc had triggered a build-time failure in the build scripts of scikits.audiolab... After all, the final error message mentions nothing of those libraries.

like image 148
Santtu Pajukanta Avatar answered Oct 20 '22 17:10

Santtu Pajukanta