BarnabyShearer / pynfc

`ctypeslib` converted libnfc and libfreefare.
https://pynfc.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
16 stars 4 forks source link

On import: "OSError: libfreefare.so: cannot open shared object file" #3

Closed OutsourcedGuru closed 5 years ago

OutsourcedGuru commented 5 years ago

Platform: Raspberry Pi 3B with Raspbian Stretch Lite mid-2018. Python 2.7.13

>>> import pynfc
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/oprint/local/lib/python2.7/site-packages/pynfc/__init__.py", line 18, in <module>
    from . import nfc, freefare, mifare
  File "/home/pi/oprint/local/lib/python2.7/site-packages/pynfc/freefare.py", line 4, in <module>
    _libraries['libfreefare.so'] = CDLL('libfreefare.so')
  File "/usr/lib/python2.7/ctypes/__init__.py", line 362, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libfreefare.so: cannot open shared object file: No such file or directory
(venv) $ sudo find / -name libfreefare* 2> /dev/null

/var/cache/apt/archives/libfreefare0_0.4.0-2+b1_armhf.deb
/var/lib/dpkg/info/libfreefare0:armhf.md5sums
/var/lib/dpkg/info/libfreefare0:armhf.shlibs
/var/lib/dpkg/info/libfreefare0:armhf.triggers
/var/lib/dpkg/info/libfreefare0:armhf.list
/usr/lib/arm-linux-gnueabihf/libfreefare.so.0
/usr/lib/arm-linux-gnueabihf/libfreefare.so.0.0.0
/usr/share/doc/libfreefare0
(venv) $ ls -l /usr/lib/arm-linux-gnueabihf/libfree*
lrwxrwxrwx 1 root root     20 Nov 10  2015 libfreefare.so.0 -> libfreefare.so.0.0.0
-rw-r--r-- 1 root root  69928 Nov 10  2015 libfreefare.so.0.0.0

Top of freefare.py itself:

from ctypes import *

_libraries = {}
_libraries['libfreefare.so'] = CDLL('libfreefare.so')
STRING = c_char_p
_libraries['libnfc.so'] = CDLL('libnfc.so')
WSTRING = c_wchar_p

Attempting a work-around...

cd /usr/lib/arm-linux-gnueabihf
sudo ln -s libfreefare.so.0.0.0 libfreefare.so

Looks like import pynfc is now happy within this context.

Continuing, then...

cd /usr/lib/arm-linux-gnueabihf
sudo ln -s libnfc.so.5.0.1 libnfc.so

I still haven't been able to get this to work with a PN532 in I2C mode but it's slightly closer, at least.

BarnabyShearer commented 5 years ago

Sorry, it looks like you actually need the -dev packages for ctypes to automatically find the correct versions for you sudo apt install libfreefare-dev.

OutsourcedGuru commented 5 years ago

You might want the folks at pypi.org to upgrade their installation instructions.

Reference: https://pypi.org/project/pynfc/