<< return to Pixycam.com

User Tools

Site Tools


wiki:v2:building_libpixyusb_as_a_python_module_on_linux

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
wiki:v2:building_libpixyusb_as_a_python_module_on_linux [2018/06/29 02:50]
pixycam old revision restored (2018/06/27 22:47)
wiki:v2:building_libpixyusb_as_a_python_module_on_linux [2019/08/08 21:12] (current)
pixycam [Python2 vs Python3]
Line 1: Line 1:
  
 ====== Using the Python API on Linux ====== ====== Using the Python API on Linux ======
- 
-We're sorry, we're working on releasing the new version of the Python API.  It is simpler to use, simpler to compile, and it is fully compatible with the Arduino API.  Libpixyusb2 will be ready on or before June 29, 2018.  ​ 
- 
- 
-/* 
- 
 ====== Introduction ====== ====== Introduction ======
  
-Pixy now has a Python wrapper for libpixyusb. For now, this is only available for Linux-based controllers (e.g. Raspberry Pi, BeagleBone). The [[wiki:v2:Building_the_libpixyusb_example_on_Linux|libpixyusb]] library provides a software application programming interface (API) for communicating with Pixy over USB. The following procedure will outline the steps to build libpixyusb ​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.
  
 This procedure assumes the following: This procedure assumes the following:
  
-  ​* Your system ​is Linux (with Debian package manager) +* Your system ​has Linux Mint installed 
-  * Pixy firmware has been updated to 1.0.2 or higher +* Your system is connected to the internet
-  * Your system is connected to the internet ​(for getting packages)+
  
-Instructions for updating ​the Pixy firmware are here: [[wiki:​v2:​Uploading_New_Firmware|Uploading New Firmware]]+Although this procedure uses Linux Mint, it should work with any Linux distribution that uses the Debian package manager (e.g. Ubuntu).
  
 +====== Procedure ======
 +===== Install dependencies for building Python SWIG module ======
 +Start a terminal application. In the terminal window type:
  
-====== 2Procedure ======+''​%%#​ sudo apt-get install swig libusb-1.0-0-dev g++ git build-essential%%''​
  
- +===== Download Pixy2 source code =====
-===== 2.1. Install dependencies for building Python SWIG module ​===== +
- +
-Start a terminal application. +
- +
- +
-==== 2.1.1. Install SWIG ==== +
- +
-In a terminal window type: +
- +
-''​%%#​ sudo apt-get install swig%%''​ +
- +
- +
-==== 2.1.2. Install libusb-1.0-0-dev ​====+
  
 In the terminal window type: In the terminal window type:
  
-''​%%sudo apt-get install libusb-1.0-0-dev%%''​ +''​%%# git clone https://​github.com/​charmedlabs/​pixy2.git ​%%''​
  
-==== 2.1.3. Install g++ (compiler) ​====+===== Build the Pixy2 SWIG module =====
  
 In the terminal window type: In the terminal window type:
  
-''​%%sudo apt-get install g++%%''​+''​%%# cd pixy2/​scripts%%''​\\ 
 +''​%%#​ ./​build_python_demos.sh%%''​
  
 +===== Try it out! =====
  
-==== 2.1.4. Install libboost ====+Change directory to the build folderIn your terminal window type:
  
-In the terminal window type:+''​%%#​ cd ../​build/​python_demos%%''​
  
-''​%%sudo apt-get install libboost-all-dev%%''​+==== Run the get blocks demo ==== 
 +Make sure your Pixy2 is connected to a USB port on your computer. Then in a terminal window type:
  
 +''​%%#​ python get_blocks_python_demo.py%%''​
  
-===== 2.2. Build the libpixyusb Python module =====+If all goes well you should see blocks:
  
 +''​%%Pixy2 Python SWIG Example -- Get Blocks%%''​\\
 +''​%%frame ​  ​0:​%%''​\\
 +''​%%[BLOCK:​ SIG=1 X=157 Y=103 WIDTH=314 HEIGHT=207]%%''​\\
 +''​%%frame ​  ​1:​%%''​\\
 +''​%%[BLOCK:​ SIG=1 X=157 Y=103 WIDTH=314 HEIGHT=207]%%''​\\
 +''​%%frame ​  ​2:​%%''​\\
 +''​%%[BLOCK:​ SIG=1 X=157 Y=103 WIDTH=314 HEIGHT=207]%%''​\\
 +''​%%frame ​  ​3:​%%''​\\
 +''​%%[BLOCK:​ SIG=1 X=157 Y=103 WIDTH=314 HEIGHT=207]%%''​\\
  
-==== 2.2.1 Download Pixy source code ====+If you don't see any block information,​ try running as superuser:
  
-In the terminal window type:+''​%%#​ sudo python get_blocks_python_demo.py%%''​
  
-''​%%git clone https://​github.com/​charmedlabs/​pixy.git%%''​+==== Run the get lines demo ==== 
 +Make sure your Pixy2 is connected to a USB port on your computer. Then in a terminal window type:
  
 +''​%%#​ python get_lines_python_demo.py%%''​
  
-==== 2.2.2. Build the Python module ====+Example output:
  
-In the terminal window type:+''​%%Pixy2 Python SWIG Example -- Get Line Features%%''​\\ 
 +''​%%frame ​  0:%%''​\\ 
 +''​%%[VECTOR:​ INDEX=1 X0= 50 Y0= 15 X1= 50 Y1=  5]%%''​\\ 
 +''​%%[VECTOR:​ INDEX=2 X0= 56 Y0=  8 X1= 67 Y1=  4]%%''​\\ 
 +''​%%frame ​  ​1:​%%''​\\ 
 +''​%%[VECTOR:​ INDEX=0 X0= 55 Y0= 27 X1= 51 Y1=  2]%%''​\\ 
 +''​%%frame ​  ​2:​%%''​\\ 
 +''​%%[VECTOR:​ INDEX=0 X0= 55 Y0= 27 X1= 51 Y1=  2]%%''​\\ 
 +''​%%frame ​  ​3:​%%''​\\ 
 +''​%%[VECTOR:​ INDEX=1 X0= 57 Y0= 31 X1= 53 Y1= 21]%%''​
  
-''%%cd pixy/​scripts%%''​\\ +If you don't see any line feature information,​ try running as superuser:
-''​%%./​build_libpixyusb_swig.sh%%''​+
  
 +''​%%#​ sudo python get_lines_python_demo.py%%''​
  
-===== 2.3. Try it out! =====+===== Errors ​=====
  
-Make sure your Pixy is connected to a USB port on your computer. Then in the terminal window type:+If you are getting an error like:
  
-''​%%cd ../​build/​libpixyusb_swig%%''​\\ +''​ImportError:​ No module named _pixy''​
-''​%%python get_blocks.py%%''​+
  
-If all goes well, you should ​see blocks:+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. 
  
-''​%%Pixy ​Python ​SWIG Example -- Get Blocks%%''​\\ +If you still get an error, you may be running into a Python ​version issue. ​ Please see the next section. ​
-''​%%[BLOCK_TYPE=0 SIG=1 X=220 Y= 17 WIDTH= 43 HEIGHT= 35]%%''​\\ +
-''​%%[BLOCK_TYPE=0 SIG=1 X=220 Y= 23 WIDTH= 42 HEIGHT= 47]%%''​\\ +
-''​%%[BLOCK_TYPE=0 SIG=1 X=220 Y= 23 WIDTH= 42 HEIGHT= 47]%%''​\\ +
-''​%%[BLOCK_TYPE=0 SIG=1 X=220 Y= 23 WIDTH= 42 HEIGHT= 47]%%''​\\ +
-''​%%[BLOCK_TYPE=0 SIG=1 X=220 Y= 23 WIDTH= 42 HEIGHT= 46]%%''​\\ +
-''​%%[BLOCK_TYPE=0 SIG=1 X=220 Y= 23 WIDTH= 45 HEIGHT= 46]%%''​\\ +
-''​%%[BLOCK_TYPE=0 SIG=1 X=219 Y= 23 WIDTH= 43 HEIGHT= 46]%%''​+
  
-If you don't see any block information,​ try running as superuser: 
  
-''​%%sudo python get_blocks.py%%''​+===== Python2 vs Python3 =====
  
 +This library will support both Python2 and Python3, but sometimes even though the Pixy Python library will compile fine, you may still see import errors when you try to run one of the Pixy Python demos. ​ This may be because you are running a different version of Python than was used to compile the Pixy Python library.  ​
  
-*/ 
  
 +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. ​  
  
wiki/v2/building_libpixyusb_as_a_python_module_on_linux.1530240653.txt.gz · Last modified: 2018/06/29 02:50 by pixycam