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 18:49] pixycam [Errors] |
||
---|---|---|---|
Line 16: | Line 16: | ||
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 ===== | ===== 2.2. Download Pixy2 source code ===== | ||
Line 22: | Line 22: | ||
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 ===== | ===== 2.3. Build the Pixy2 SWIG module ===== | ||
Line 32: | Line 32: | ||
===== 2.4. Try it out! ===== | ===== 2.4. Try it out! ===== | ||
+ | |||
+ | Change directory to the build folder. In your terminal window type: | ||
+ | |||
+ | ''%%# cd ../build/python_demos%%'' | ||
==== 2.4.1. Run the get blocks demo ==== | ==== 2.4.1. 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 ==== | ==== 2.4.2. 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 can 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 and see what version is run by looking at the version information that's printed to the console. | ||
+ | |||
+ | 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. | ||