gijzelaerr / python-snap7

A Python wrapper for the snap7 PLC communication library
http://python-snap7.readthedocs.org/
MIT License
643 stars 246 forks source link

RuntimeError: "can't find snap7 library" on Raspbian GNU/Linux 10 (buster) #374

Closed ts4iot closed 2 years ago

ts4iot commented 2 years ago

I get the following error on a fresh installed Raspian buster:

_Python 3.7.3 (default, Jan 22 2021, 20:04:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import snap7
>>> g_plc = snap7.client.Client()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/deviceadmin/.local/lib/python3.7/site-packages/snap7/client.py", line 64, in __init__
    self._library = load_library(lib_location)
  File "/home/deviceadmin/.local/lib/python3.7/site-packages/snap7/common.py", line 72, in load_library
    return Snap7Library(lib_location).cdll
  File "/home/deviceadmin/.local/lib/python3.7/site-packages/snap7/common.py", line 63, in __init__
    raise RuntimeError("can't find snap7 library. If installed, try running ldconfig")
RuntimeError: can't find snap7 library. If installed, try running ldconfig_

python-snap7 is successfully installed with: sudo pip3 install python-snap7

Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting python-snap7
  Downloading https://www.piwheels.org/simple/python-snap7/python_snap7-1.2-py3-none-any.whl
Installing collected packages: python-snap7
Successfully installed python-snap7-1.2

Is it possible to install the missing library?

swamper123 commented 2 years ago

Have you tried exeuting sudo ldconfig and tried it again?

ts4iot commented 2 years ago

Yes, but without success.

ts4iot commented 2 years ago

With Raspbian GNU/Linux 9 (stretch) I had no problem. I have now copied the library /usr/lib/libsnap7.so.1 from Stretch to Buster and run the command sudo ldconfig.

Now it works. But why is the library not installed on Buster?

swamper123 commented 2 years ago

pyton-snap7 is a wrapper around the library of snap7. Normally it got installed within the wheel process as well (including the ldconfig part). So not sure what happened here. In such cases a manual install has to be done.

gijzelaerr commented 2 years ago

does dpkg --print-architecture give armhf and getconf LONG_BIT 32 bit? Wheels are not supported for ARM 32-bit installations, so it falls back on a source install, which doesn't include the .so file. You need to manually install the .so file, which you somehow also did on your stretch machine.

gijzelaerr commented 2 years ago

created follow-up issue: https://github.com/gijzelaerr/python-snap7/issues/376

gijzelaerr commented 2 years ago

I also noticed you are using wheels from https://www.piwheels.org/, which are not made by us and not supported by us. It seems this is a 3rd party service that builds our wheels without including the so.

ts4iot commented 2 years ago

Yes I can confirm. dpkg --print-architecture gives armhf and getconf LONG_BIT returns 32. I cannot remember to install it on Stretch, but it was long time ago.

ts4iot commented 2 years ago

It is a Raspberrypi based hardware platform.

https://revolutionpi.de/

cmoutafidis commented 11 months ago

@gijzelaerr can you provide further information on how to manually install the .so file?

Edit: All good, I found this post that explains the steps in the comments: https://support.industry.siemens.com/forum/gr/en/posts/how-do-i-install-the-snap7-library/192979

nikteliy commented 11 months ago

@cmoutafidis @ts4iot You could try installing this package. It's built for the armv7l arch.

@gijzelaerr I think we haven't added armv7l package to PyPI yet

gijzelaerr commented 11 months ago

thanks @nikteliy, good point. i've uploaded the wheel, 1.3 should now be installable on armv7l. @cmoutafidis can you verify?