Skip to content

Instantly share code, notes, and snippets.

@dbogdanov
Created July 3, 2018 17:44
Show Gist options
  • Save dbogdanov/5fb19c2b0ab4dff8f078a3565d4b5176 to your computer and use it in GitHub Desktop.
Save dbogdanov/5fb19c2b0ab4dff8f078a3565d4b5176 to your computer and use it in GitHub Desktop.
Building Python extension on Windows

Building Essentia's Python extension on Windows

Python.org Windows binaries are compiled against an MS Visual C++ (MSVC) runtime, which version differs with different Python versions. Essentia's Python extension should be built with MSVC too because the MinGW C++ library builds won't be compatible with MSVC.

In this guide we use VirtualBox Windows machine.

Preparing build environment

Building dependencies

FFMPEG

There are FFmpeg builds available online (http://ffmpeg.zeranoe.com/builds/), but unfortunately those do not include libavresample. Therefore, we are building FFmpeg from scratch:

  • Install MSYS2: http://www.msys2.org/

  • Install Yasm: download the yasm-*.exe file, rename to yasm.exe and copy to C:\workspace

  • Install pre-requisites in MSYS2 terminal: pacman -S tar make gcc diffutils

  • Open "x86 Native Tools Command Prompt for VS 2017" and from this terminal open the Msys2 terminal (use the following flags to inherit %PATH% variable): C:\msys64\msys2_shell.cmd -msys -use-full-path

  • Go to the root Essentia folder (cd /c/ to access C:)

  • cd packaging/win32_3rdparty/

  • Build ffmpeg: ./build_ffmpeg_msvc.sh

  • Create *.lib export files

cd lib/
lib /def:avcodec-56.def /out:avcodec-56.lib
lib /def:avformat-56.def /out:avformat-56.lib
lib /def:avutil-54.def /out:avutil-54.lib
lib /def:avresample-2.def /out:avresample-2.lib
lib /def:swresample-1.def /out:swresample-1.lib

Rename:

avcodec-56.lib --> avcodec.lib
avformat-56.lib --> avcodec.lib
avutil-54.lib --> avutil.lib
avresample-2.lib --> avresample.lib
swresample-1.lib --> swresample.lib

FFTW

FFTW builds are available online: ftp://ftp.fftw.org/pub/fftw/fftw-3.3.3-dll32.zip (32-bit)

  • Generate .lib import file from .def file: http://www.fftw.org/install/windows.html
  • Keep the dll filename as it is, but rename the rest of files from libfft3f-3.* to fft3f.* to make waf find them (waf does not add "lib" prefix to the filenames)

Libsamplerate

We are providing prebuilt library files.

  • Rename files: libsamplerate-0.lib --> samplerate.lib

Taglib

Build from source:

Steps:

  • Install cmake: https://cmake.org/

  • cmake -DCMAKE_INSTALL_PREFIX=C:\users\User\Dev\lib

  • msbuild all_build.vcxproj /p:Configuration=Release

  • msbuild install.vcxproj

  • When build is done, copy files to packaging/win32_3rdparty (the dll file is in taglib/Release folder)

  • Patch taglib.pc

Building Essentia

  • Open "x86 Native Tools Command Prompt for VS 2017"
  • Configure Essentia: python waf configure --with-python --msvc_targets="x86"
  • Compile and install:
python waf
python waf install

The waf script will install:

  • library binary and headers to C:\Users\User\AppData\Local\Temp\include\essentia\ and C:\Users\User\AppData\Local\Temp\lib\

  • Python extension to C:\Users\User\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\essentia

  • In the case of import error in python due to missing DLLs, use Dependency Walker to find out missing dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment