<< return to Pixycam.com

Python on Raspberry pi not working

Hello everyone.
With the FRC opener fast approaching, I am taking this vacation to try to finalize some of our on-robot code. I a difficult time all of a sudden getting the python libraries to work with our robot. Here is what we had working last year.
Plugged the Pixy into a Raspberry pi (last year it was a 3) running the frc vision library, and output a string into network tables that we read on the RoboRIo.

However, this year, with a new pi (4), and a new vision library image, I cannot get the python libraries to build.

Here is what I am doing…
Hardware, bypass the rio, and connecting directly to the Raspberry Pi using putty and ethernet cable.

Software…

  • Installed a fresh OS using this image (2020.1.1).
  • I installed updates, and added dependencies.
  • Then, I went to download and install the Pixy software.
  • There was a certificate error, so I bypassed the certificate in gitclone)
  • Attempted to run the build_all script. CPP built fine, but Python had a fatal error.
building '_pixy' extension
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-9NJ3qw/python2.7-2.7.16=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -D__LINUX__=1 -I/usr/include/libusb-1.0 -I/usr/local/include/libusb-1.0 -I../../../common/inc -I../../../host/libpixyusb2/include/ -I../../../host/arduino/libraries/Pixy2 -I/usr/include/python2.7 -c pixy_wrap.cxx -o build/temp.linux-armv7l-2.7/pixy_wrap.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
pixy_wrap.cxx:173:11: fatal error: Python.h: No such file or directory
 # include <Python.h>
           ^~~~~~~~~~
compilation terminated.
error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
rm: cannot remove '../../../../build/python_demos/*.so': No such file or directory
cp: -r not specified; omitting directory 'build'
SUCCESS

Then, I tried running the code, and got this error…

  File "get_lines_python_demo.py", line 2, in <module>
    import pixy
  File "/home/pi/pixy/pixy2/build/python_demos/pixy.py", line 168, in <module>
    class IntersectionArray(_object):
  File "/home/pi/pixy/pixy2/build/python_demos/pixy.py", line 181, in IntersectionArray
    __swig_destroy__ = _pixy.delete_IntersectionArray
AttributeError: module '_pixy' has no attribute 'delete_IntersectionArray

Do you have any ideas what I am doing wrong? Thank you for the incredible device and support.

The CPP version works fine. Yet none of the Python files run. I tried in Python 2 as well.

Sincerely,
Mr. R^2

Edit: I think I got it to work. I went back to the old tutorials, and saw they needed another library. I ran the following code…

sudo apt-get install libboost-all-dev

And it seems to be working now. Thanks again.

Glad you got it working! And thanks for following up with the fix!

Do let us know if you need anything else, and good luck this season!

Cheers,
Jesse

Most of the time these are dependency-issues. Python.h is used by GNU Compiler Collection (gcc) to build applications. You need to install a package called python-dev for building Python modules, extending the Python interpreter or embedding Python in applications. You encounter “Python.h: No such file or directory” error while trying to build a shared library using the file extension of another language ( e.g. ‘C’ ). If you are trying to build a shared library using the file extension of another language, you need to install the correct development version of Python.

Reason for this error:

  • You haven’t properly installed the header files and static libraries for python dev.
  • Also, sometimes include files might not be default in the include path.

How to solve this error:

  • Install the missing files and libraries.
  • Include Path and Library.
  • Finally, Compile it.

Hello,
I’m not sure how to respond. Perhaps you are having trouble getting Python support working on an Raspberry Pi? If so, follow the steps in this guide:

https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:building_libpixyusb_as_a_python_module_on_linux

Edward