毎回も忘れ、毎回も時間かけて探し解決方法見つかる。
とりあえずメモしておく。
Linux
- まずSNAP7ライブラリをダウンロードする(この例は1.2.1)
- 解凍する
- tar -zxvf snap7-full-1.2.1.tar.gz
- コンパイルする(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
- コンパイル後のライブラリを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
- 一応pipをInstall
- sudo apt-get install python-pip
- python-snap7インストール
- sudo pip install python-snap7
それでもなぜかImportできなかった。そしてもう一度エラーをみたら。
多分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
こうしたら無事に行けました!
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
これです。
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