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 [2018/07/24 07:18] hohenheim [Using the Python API on Linux] |
wiki:v2:building_libpixyusb_as_a_python_module_on_linux [2019/08/08 21:09] pixycam [Errors] |
||
---|---|---|---|
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%%'' | + | ''%%# 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: | ||
- | ''%%# git clone https://github.com/charmedlabs/pixy2 %%'' | + | ''%%# 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! ===== |
- | ==== 2.4.1. Run the get blocks demo ==== | + | Change directory to the build folder. In your terminal window type: |
+ | |||
+ | ''%%# cd ../build/python_demos%%'' | ||
+ | |||
+ | ==== 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: | ||
- | ''%%# cd ../build/python_demos%%''\\ | ||
''%%# python get_blocks_python_demo.py%%'' | ''%%# python get_blocks_python_demo.py%%'' | ||
Line 53: | Line 56: | ||
If you don't see any block information, try running as superuser: | If you don't see any block information, try running as superuser: | ||
- | ''%%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: | ||
- | ''%%# cd ../build/python_demos%%''\\ | ||
''%%# python get_lines_python_demo.py%%'' | ''%%# python get_lines_python_demo.py%%'' | ||
Line 72: | Line 74: | ||
''%%[VECTOR: INDEX=0 X0= 55 Y0= 27 X1= 51 Y1= 2]%%''\\ | ''%%[VECTOR: INDEX=0 X0= 55 Y0= 27 X1= 51 Y1= 2]%%''\\ | ||
''%%frame 3:%%''\\ | ''%%frame 3:%%''\\ | ||
- | ''%%[VECTOR: INDEX=1 X0= 57 Y0= 31 X1= 53 Y1= 21]%%''\\ | + | ''%%[VECTOR: INDEX=1 X0= 57 Y0= 31 X1= 53 Y1= 21]%%'' |
+ | |||
+ | If you don't see any line feature information, try running as superuser: | ||
+ | |||
+ | ''%%# 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 the current directory and error should go away. | ||
+ | |||
+ | 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. | ||