Hey, all, developer here.
I was recently attempting to use the PyAudio framework (http://people.csail.mit.edu/hubert/pyaudio/) to ‘quickly’ test some audio features of a windows 7 box. Since there are no python bindings for the x64 bit version of python (msvc) which I am using, I figured that I’d go ahead and build the source. Unfortunately, there are some gotchas.
First of all, just a bit of banter – basically we are using msvc, and not mingw, feel free to skip the following paragraph unless you are interested in why I am using msvc.
If you are developing python and running extensions on windows, you have two main toolchains to pick from, msvc and msys(mingw). I pick msvc, not because I have anything against mingw, but because in my experience msvc integrates more cleanly, and you don’t end up having to deal with complex pathing problems from various multiple-step build processes found in Unix. In addition this, there are frequently name-mangling issues, undocumented special flags which need to be passed to the mingw systems, and, worst of all, you will often realize that you want to integrate with some msvc built system down the road which your app now has to find a way to talk to, or you will have to recompile your entire build. So, I will not be covering PyAudio x64 for mingw – if you are on a Windows environment, you might want to accept that you are going to be doing things in a Windows manner. I suggest using Linux if you are dead set against anything made by Microsoft – but then why are you here?
The pre-reqs for the build are as follows:
- A working copy of python (in my case 2.7), x64, built using msvc. You should be able to obtain this from the Python website. Ensure that you can call this version of python from the cmd line.
- A working copy of Visual Studio 2008, either Express or full will do. Since it is difficult to find these tools, you can obtain them here:
- Failing Visual Studio 2008, you can attempt the build using Visual Studio 2010, however this will complicate the build and will require you to setup some magic with the VS90COMNTOOLS variable, basically pointing Python’s build system at the correct version of Visual Studio (distutils bugfix maybe?). FTR, I have both installed on my machine – Python is currently build using VS2008, however I imagine that will eventually change. Alternatively, you can e-mail me or leave a comment and I will attempt to get you a copy of VS2008 as best as I am able to.
- A working copy of the Windows 7 SDK. This tool gives you the cross compilers you need to compile for x64.
- Configure all these tools, make sure vcvarsall.bat and setenv.cmd are in your path, or at least that you know where they are and can call them. If you don’t know what to configure, then you can likely leave them alone and call the following commands outright.
Quickly, my vcvarsall can be found at C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\, and my setenv.cmd can be found at C:\Program Files\Microsoft SDKs\Windows\v7.0\Bin\
- Checkout the source:
- Either use:
git clone http://people.csail.mit.edu/hubert/git/pyaudio.git
- Or you can use the release version from the website
- Or you can (if you have pip installed and configured): ‘pip install –no-install pyaudio’ and then you can find your PyAudio folder inside C:\temp\pip-build\pyaudio (note, pip-build will be suffixed by your username)
- Download patches.7z
- Download setupScripts.7z
- Download portaudiolibs.7z
- Dump the contents of patches.7z into your source directory. Note: hopefully these patches will make their way into the official source tree, but they may still be of use for the release versions
- Extract portaudiolibs.7z and put the folder in the root source directory.
- Once you have the source patched, you can setup your build environment. I recommend putting both of these files (from setupScripts.7z) somewhere on your path (a home bin directory for example) for easier access.
- Run the provided win7sdk.bat from within the cmd-line
- Run the provided pythonDev.bat from within the cmd-line
- Run setup.py build –static-link
- Run setup.py install
- Test that your build works by running the examples in test
You should have installed pyaudio into your python installation, if you have trouble let me know. I will be updating these steps and will help clarify things where and when I can.
Good luck and Happy Coding!