Thursday, November 10, 2011

Installing the Marsyas Python bindings on Windows 7


In this post I assume you have followed the instructions from the previous post about installing Marsyas on Windows 7. To install the Python bindings you need to perform the following steps (I used Python 2.6 but I suspect that things should also work with Python 2.7). The python bindings to Marsyas do not require NumPy/SciPy and Matplotlib to work however having these package enables the creation of beautiful plots similar to MATLAB that help a lot with prototyping.

  1. Install Python 2.6 using the MSI Installer 
  2. Install NumPy using the superpack binary numpy-1.6.1-win32-superpack-python2.6.exe
  3. Install SciPy using the superback binary  scipy-0.10.0rc1-win32-superpack-python2.6.exe
  4. Install Matplotlib. I used matplotlib-1.1.0.win32-py2.6.exe from the Download link of the matplotlib website. 
Now you should be able to get nice MATLAB looking graphs in Python. To test start the Python command-line (or IDLE or whatever other method you have of editing Python code) and do:
>>> from pylab import *;
>>> x = randn(1000);
>>> hist(x);
>>> show() 
You should see a histogram plot of a rough bell-shape curve that will look something like this:



Congratulations you have a working Python/NumPy/SciPy matplotlib system. 

The next step is to install swig that is the program that generates the Python bindings. Download the archive that contains a pre-built executable for windows: http://prdownloads.sourceforge.net/swig/swigwin-2.0.4.zip Unzip the file. The next step will help ensure that swig and python can be found by CMake and consists of editing your PATH environment variable to point to the Python executable as well as the swig executable.

Right-click on Computer then select Properties and then select Advanced System Settings and Environment Variables.Under System Variables you will see the Path. Edit the path to add Python2.6 and swig.exe to it.





For example my Path looks like:
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\ProgramFiles\Internet Exporer;C:\Program Files\CMake 2.8\bin;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\TortoiseSVN\bin;C:\Python26;C:\swigwin-2.0.4;

 Now we are ready to configure Maryas with the Python bindings using CMake. This can be done by ticking the WITH_SWIG option. If everything gets detected correctly the pink options will turn into grey and swig and python will be detected. This is how it looks on my machine:



 

Click generate and the Microsoft Visual Studio C++ Express solution file will be updated accordingly. 

The last part requires that you run Visual Studio as an administrator in order to be able to install the bindings and corresponding DLL to the default Python location for modules. To do that right-click on the icon for Visual Studio and select Run as Administrator. If needed confirm that you want to run as administrator and reopen the marsyas.sln file from the Marsyas build directory.

Right click on the ALL_BUILD target and select build to compile Marsyas. When all projects are finished then right click on the INSTALL target and select build.





Now all the Marsyas related stuff is installed. Check that the python related entries at the end go to the right directory especially if you have multiple version of Python installed.

Now you are ready for the final step. Start the Python 2.6 command-line and type:
import marsyas 
If there are no problems the Marsyas python bindings are installed. Now you are ready to explore the code in src/marsyas_python. For example you can load src/marsyas_python/windowing.py into Idle and click F5 to run. You should see a nice looking plot demonstrating the effect of windowing to the spectrum of sinusoid signals that are not aligned with the DFT bins.



Happy hacking !!!

2 comments:

  1. I wonder if this would actually work with python2.7. I remember swig + python2.7 giving me some problems on windows that didn't happen on Linux.

    The problem could have been from the pyBox2d library I was compiling and not swig though.

    ReplyDelete
  2. I have a hard time describing my thoughts on content, but I really felt I should here. Your article is really great. I like the way you wrote this information. Angular developer

    ReplyDelete