I want to read and write RC522 RFID by using raspberry pi. For that I want configure SPI communication. First I enable SPI in raspi.config. After that I tried to download SPI-Py package to enable SPI communication for Python from this link https://github.com/lthiery/SPI-Py. I already update python and python 3 by using this command;

sudo apt-get install python-dev and python3-dev

I use this commands;

git clone https://github.com/lthiery/SPI-Py

and install it via

sudo python setup.py install 

This SPI-Py folder is in /home/pi directory.

Then this error came.

raspberrypi root @: ~ # cd / home / pi / SPI-py   
raspberrypi root @ :/ home / pi / SPI-py # sudo python setup.py install   
running install   
running build   
running build_ext  
building 'spiritual' extension  
gcc-pthread-fno-strict-aliasing-DNDEBUG-g-fwrapv-O2-Wall-Wstrict-prototypes-fPIC -I/usr/include/python2.7-c-o spi.c build/temp.linux-armv6l- 2.7/spi.o  
spi.c: 20:20: fatal error: Python.h: No such file or directory  
compilation terminated.  
error: command 'gcc' failed with exit status 1

How to solve this error?

  • on line that says gcc-pthread-fno-strict-aliasing-DNDEBUG-g-fwrapv-O2-Wall-Wstrict-prototypes-fPIC -I/usr/include/python2.7-c-o spi.c build/temp.linux-armv6l- 2.7/spi.o I noticed there is no spaces between arguments (as in between python2.7 and the following -c and so on). Is this a formatting problem on your question or does it appears the same way on your machine ? – Shreyas Murali Sep 23 '16 at 22:13

You need to install the Python development environment (part of the environment is the missing python.h).

For Python 2: sudo apt-get install python-dev

For Python 3: sudo apt-get install python3-dev

| improve this answer | |
  • I installed both of these but same problem. I found the solution of it I already put on comment. Thank you. – iNdra Jul 28 '15 at 17:07

As the error states, you need to install Python 2.7. Please try the below command:

sudo apt-get install python2.7
| improve this answer | |
  • Python2.7 is already the newest version. python2.7 set to manually installed. 0 upgraded, 0 newly installed, 0 to remove and 129 not upgraded. This is the massage. But same problem. – iNdra Jul 28 '15 at 15:00
  • OK. Can you try compiling this SPI library: github.com/doceme/py-spidev. This works for me. – Prashant Jul 28 '15 at 15:03
  • running install running build running build_ext running install_lib copying build/lib.linux-armv6l-2.7/spidev.so -> /usr/local/lib/python2.7/dist-packages error: /usr/local/lib/python2.7/dist-packages/spidev.so: Permission denied – iNdra Jul 28 '15 at 15:10
  • Please try it with "sudo" – Prashant Jul 28 '15 at 15:28
  • git clone github.com/doceme/py-spidev and sudo python setup.py install this is what i tried. is it wrong ? – iNdra Jul 28 '15 at 15:33

I tried this http://geraintw.blogspot.com/2014/01/rfid-and-raspberry-pi.html Its work for me.

> sudo apt-get install python-dev git clone
> https://github.com/lthiery/SPI-Py.git
> cd SPI-Py sudo python setup.py
> install
| improve this answer | |
  • It could be nice to include the essential parts of the link (that could becomes unreachable) in your answer – mpromonet Oct 26 '15 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.