mxgxw / MFRC522-python

A small class to interface with the NFC reader Module MFRC522
GNU Lesser General Public License v3.0
521 stars 419 forks source link

Read.py (MFRC522.py) throws error on import spi #77

Closed bagriz closed 4 years ago

bagriz commented 4 years ago

When I am trying to run Read.py with python Read.py than I get always the following error message:

Traceback (most recent call last):
  File "Read.py", line 25, in <module>
    import MFRC522
  File "/home/pi/MFRC522-python/MFRC522.py", line 25, in <module>
    import spi
ImportError: /usr/local/lib/python2.7/dist-packages/spi.so: file too short

SPI is enabled and SPI-py is also set-uped:

pi@raspberrypi:~/SPI-Py $ lsmod | grep -i spi
spidev                  7903  0
spi_bcm2835             7915  0
pi@raspberrypi:~/SPI-Py $ ls -l /dev/spi*
crw-rw---- 1 root spi 153, 0 Jul 28 22:03 /dev/spidev0.0
crw-rw---- 1 root spi 153, 1 Jul 28 22:03 /dev/spidev0.1

But when I am checking the corrupted spi.so file than I can see that it is empty:

pi@raspberrypi:/usr/local/lib/python2.7/dist-packages $ ls -l
total 4
-rw-r--r-- 1 root staff 314 Jul 28 22:48 SPI_Py-1.0.egg-info
-rwxr-xr-x 1 root staff   0 Jul 28 00:53 spi.so

I have now idea what I have to do here now to make import spi possible to make Read.py working.

Can anyone maybe help me here. This would be great. Thank you very much for your support.

bagriz commented 4 years ago

Finally I could manage to fix this problem by myself. Hallelujah ;)

I have removed (sudo rm -rf SPI-py) directory and cloned it once again from GIT repo to my cd ~

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

Due to the fact, that the currect SPI-py version is a litte bit buggy, it was necessary to rollback SPI-py to a commit before February 17th. Therefore you have to navigate to your SPI-py folder and run:

git checkout 8cce26b9ee6e69eb041e9d5665944b88688fca68

After the rollback was successfull it is necessary to install SPI-py once again:

sudo python setup.py install

After this I was able to run Read.py and read from my RFID chips without any errors.