With a few steps, you can build your own Python 3.3.0 wrapper.
On Windows:
Building LeapPython.pyd on Windows (32-bit Python 3.3.0 for this example) :
-
Install Visual Studio (any of 2008, 2010, or 2012 should be fine), Python 3.3.0 for Windows x86, and swig-2.0.9.
-
Create an empty C++ project. Copy Leap.h, LeapMath.h, Leap.i, and Leap.lib (x86) into this project folder.
-
From that folder, run SWIG to generate LeapPython.cpp. For example:
c:\leap_python33>"C:\Program Files (x86)\swigwin-2.0.9\swig.exe" -c++ -python -o LeapPython.cpp -interface LeapPython Leap.i
-
Open up the project properties, select the Release configuration, and go to the Configuration Properties -> General page. From there, set the 'Target Name' to LeapPython and set the 'Configuration Type' to 'Dynamic Library (.dll)'. (screenshot)
-
Go to to the C/C++ -> General property page. Add the path containing Python.h, typically
C:\Python33\include
. (screenshot) -
Go to the Linker -> Input property page. Add Leap.lib and the full path to python33.lib, typically
C:\Python33\libs\python33.lib
. (screenshot) -
Press F7 to build. (If you hit errors such as missing symbols, this tends to come from accidentally omitting one library or mixing x86 with x64. Double-check that you have the correct Leap.lib and python33.lib (from 32-bit Python) and are building a Win32 configuration.)
-
Rename the output LeapPython.dll to LeapPython.pyd
If you need 64-bit Python, create the x64 configuration in Visual Studio and change some of the above steps to use x64 libraries accordingly.
The process on Mac OS X is generally easier.
On Mac:
Building LeapPython.so on Mac :
-
Install XCode along with its command-line tools, Python 3.3.0 for Mac, and swig-2.0.9 (likely using MacPorts).
-
Copy Leap.h, LeapMath.h, Leap.i, and libLeap.dylib into one folder.
-
Generate LeapPython.cpp with
swig -c++ -python -o LeapPython.cpp -interface LeapPython Leap.i
-
Compile and link with
clang++ -arch i386 -arch x86_64 -I/Library/Frameworks/Python.framework/Versions/3.3/include/python3.3m LeapPython.cpp libLeap.dylib /Library/Frameworks/Python.framework/Versions/3.3/lib/libpython3.3.dylib -shared -o LeapPython.so
Running the Sample Python app:
You can take your resulting LeapPython.pyd (LeapPython.so on Mac) and run the Sample application alongside Leap.py and Leap.dll (libLeap.dylib on Mac). You'll naturally have to make some changes to adhere to Python 3, such as parentheses around arguments to the 'print' function and replacing the line using the '/=' operator with: pos = pos.__div__(numFingers)
Mac command-line:
`$ python3 SamplePython33.py
Initialized
Press Enter to quit...
Connected
Frame id: 98019, timestamp: 909519145, hands: 0, fingers: 0, tools: 0
‰Û_`
On Linux:
Please see Akishin's tutorial on building LeapPython for Python 3+ on Ubuntu
Conclusion
In the attached zip file I have included sample wrappers built with the above procedure, as well as a Sample.py modified for Python 3.
Our hope is that this approach will not only work for users interested in Python 3, but also serve as a solution for those who have requested other versions of Python for which we don't yet provide binaries. For example, we have heard requests for Python 2.7.1, Python 2.6.2, and even alternative builds of Python 2.7.3. We're looking for ways to best meet the needs of our Python users without letting this turn into a maintenance nightmare of Python versioning.
0 Comments