This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
wiki:v2:building_libpixyusb_as_a_python_module_on_linux [2019/05/06 21:52] pixycam |
wiki:v2:building_libpixyusb_as_a_python_module_on_linux [2019/08/08 21:07] pixycam [Python2 vs Python3] |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Using the Python API on Linux ====== | ====== Using the Python API on Linux ====== | ||
- | ====== 1.0. Introduction ====== | + | ====== Introduction ====== |
Pixy2 now has a Python wrapper for libpixyusb2. For now, this is only available for Linux-based controllers (e.g. Raspberry Pi, BeagleBone). The [[wiki:v2:building_the_libpixyusb_example_on_linux|libpixyusb2]] library provides a software application programming interface (API) for communicating with Pixy2 over USB. The following procedure will outline the steps to build libpixyusb2 as a Python module. | Pixy2 now has a Python wrapper for libpixyusb2. For now, this is only available for Linux-based controllers (e.g. Raspberry Pi, BeagleBone). The [[wiki:v2:building_the_libpixyusb_example_on_linux|libpixyusb2]] library provides a software application programming interface (API) for communicating with Pixy2 over USB. The following procedure will outline the steps to build libpixyusb2 as a Python module. | ||
Line 12: | Line 12: | ||
Although this procedure uses Linux Mint, it should work with any Linux distribution that uses the Debian package manager (e.g. Ubuntu). | Although this procedure uses Linux Mint, it should work with any Linux distribution that uses the Debian package manager (e.g. Ubuntu). | ||
- | ====== 2.0. Procedure ====== | + | ====== Procedure ====== |
- | ===== 2.1. Install dependencies for building Python SWIG module ====== | + | ===== Install dependencies for building Python SWIG module ====== |
Start a terminal application. In the terminal window type: | Start a terminal application. In the terminal window type: | ||
''%%# sudo apt-get install swig libusb-1.0-0-dev g++ git build-essential%%'' | ''%%# sudo apt-get install swig libusb-1.0-0-dev g++ git build-essential%%'' | ||
- | ===== 2.2. Download Pixy2 source code ===== | + | ===== Download Pixy2 source code ===== |
In the terminal window type: | In the terminal window type: | ||
Line 24: | Line 24: | ||
''%%# git clone https://github.com/charmedlabs/pixy2.git %%'' | ''%%# git clone https://github.com/charmedlabs/pixy2.git %%'' | ||
- | ===== 2.3. Build the Pixy2 SWIG module ===== | + | ===== Build the Pixy2 SWIG module ===== |
In the terminal window type: | In the terminal window type: | ||
Line 31: | Line 31: | ||
''%%# ./build_python_demos.sh%%'' | ''%%# ./build_python_demos.sh%%'' | ||
- | ===== 2.4. Try it out! ===== | + | ===== Try it out! ===== |
Change directory to the build folder. In your terminal window type: | Change directory to the build folder. In your terminal window type: | ||
Line 37: | Line 37: | ||
''%%# cd ../build/python_demos%%'' | ''%%# cd ../build/python_demos%%'' | ||
- | ==== 2.4.1. Run the get blocks demo ==== | + | ==== Run the get blocks demo ==== |
Make sure your Pixy2 is connected to a USB port on your computer. Then in a terminal window type: | Make sure your Pixy2 is connected to a USB port on your computer. Then in a terminal window type: | ||
Line 58: | Line 58: | ||
''%%# sudo python get_blocks_python_demo.py%%'' | ''%%# sudo python get_blocks_python_demo.py%%'' | ||
- | ==== 2.4.2. Run the get lines demo ==== | + | ==== Run the get lines demo ==== |
Make sure your Pixy2 is connected to a USB port on your computer. Then in a terminal window type: | Make sure your Pixy2 is connected to a USB port on your computer. Then in a terminal window type: | ||
Line 79: | Line 79: | ||
''%%# sudo python get_lines_python_demo.py%%'' | ''%%# sudo python get_lines_python_demo.py%%'' | ||
+ | |||
+ | ===== Errors ===== | ||
+ | |||
+ | If you are getting an error like: | ||
+ | |||
+ | ''ImportError: No module named _pixy'' | ||
+ | |||
+ | Python is having trouble finding the Pixy Python library. This may be because you are running in another directory. Just copy over the \_pixy.so and pixy.py files in the ''pixy2/build/python_demos'' directory to your directory and it should work. | ||
+ | |||
+ | If you still get an error, you may be running into a Python version issue. Please see the next section. | ||
+ | |||
+ | |||
+ | ===== Python2 vs Python3 ===== | ||
+ | |||
+ | This library will support both Python2 and Python3, but sometimes it will compile fine but provide import errors when you try to run one of the Python demos. | ||
+ | |||
+ | |||
+ | If you want Python3 support, for example, make sure that your default "python" is Python3 before running ''build\_python\_demos.sh''. That is, make sure that Python3 is the version of Python that runs when you type in the "python" command in your shell. You can test this by running "python --version" at the shell prompt. | ||
+ | |||
+ | If it's not version 3 (or higher), change the default version to be Python3. The recommended way to do this may depend on your Linux distribution. | ||