Forget every time, and spend time searching and finding a solution every time. Make a note for the time being.
Linux
https://stackoverflow.com/questions/24343557/cant-find-snap7-library-linux
--First download the SNAP7 library (this example is 1.2.1) - wget http://sourceforge.net/projects/snap7/files/1.2.1/snap7-full-1.2.1.tar.gz/download --Unzip - tar -zxvf snap7-full-1.2.1.tar.gz --Compile (arm_v6_linux.mk is used for RPI 1. For RPI 2 use arm_v7_linux.mk) - cd snap7-full-1.2.1/build/unix && sudo make -f arm_v6_linux.mk all --Compiled library to lib - sudo cp ../bin/arm_v6-linux/libsnap7.so /usr/lib/libsnap7.so - sudo cp ../bin/arm_v6-linux/libsnap7.so /usr/local/lib/libsnap7.so --Install pip for the time being - sudo apt-get install python-pip --python-snap7 installation - sudo pip install python-snap7
Still, I couldn't import it for some reason. And if you see the error again. Maybe there is something in common.py!
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/snap7/client.py", line 29, in __init__
self.library = load_library()
File "/usr/local/lib/python2.7/dist-packages/snap7/common.py", line 48, in load_library
return Snap7Library(lib_location).cdll
File "/usr/local/lib/python2.7/dist-packages/snap7/common.py", line 40, in __init__
raise Snap7Exception(msg)
snap7.exceptions.Snap7Exception: can't find snap7 library. If installed, try running ldconfig
I was able to go safely!
class Snap7Library(object):
"""
Snap7 loader and encapsulator. We make this a singleton to make
sure the library is loaded only once.
"""
_instance = None
def __new__(cls, *args, **kwargs):
if not cls._instance:
cls._instance = object.__new__(cls)
cls._instance.lib_location = None
cls._instance.cdll = None
return cls._instance
def __init__(self, lib_location=None):
if self.cdll:
return
#Change here
#self.lib_location = lib_location or self.lib_location or find_library('snap7')
self.lib_location = 'your lib location'
if not self.lib_location:
msg = "can't find snap7 library. If installed, try running ldconfig"
raise Snap7Exception(msg)
self.cdll = cdll.LoadLibrary(self.lib_location)
Window
This.
The folder where the snap7.dll and .lib file are located must be present in the Enviroment variables of Windows.
https://stackoverflow.com/questions/33697263/python-snap7-windows-cant-find-snap7-library
Recommended Posts