fixed build for python3

Fixed so that it will build on python3. Perhaps consider adding another branch?

Also moved a declaration to beginning of the function to fix an error that is thrown with some compiler configurations.

Had to comment out SPI in setup.py to get it to build.