can't find snap7 library - linux

FlixMa picture FlixMa · Jun 21, 2014 · Viewed 7.8k times · Source

I'm running Rapbian on a Raspberry Pi Revision B.

I downloaded the module python-snap7 as instructed on this webpage: Snap7 Installation

I tried it twice: One time using pip and another doing it manually. However, I installed it then via setup.py build and then setup.py install.

If i try to create a client, I get the following error:

Python 2.7.3 (default, Mar 18 2014, 05:13:23)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import snap7
>>> c = snap7.client.Client()
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 did the following after getting this error:

I added some lines to the file so it looks like the following:

include /etc/ld.so.conf.d/*.conf
include /usr/local/lib/python2.7/dist-packages/snap7-full-1.2.1/
include /usr/local/lib/python2.7/dist-packages/snap7-full-1.2.1/release/Linux/ARMHF/Raspberry/
include /usr/local/lib/python2.7/dist-packages/snap7-full-1.2.1/src/lib/
include /usr/local/lib/python2.7/dist-packages/snap7-python/build/lib.linux-armv6l-2.7/snap7/
include /usr/local/lib/python2.7/dist-packages/snap7-python/

Then I issued the command sudo ldconfig to update the cache file /etc/ld.so.cache, but the error stays :(

  1. Is it right to have the include instruction in fornt of each line?
  2. Is there any kind of critical error I just don't see?
  3. Which library do i need to include ? I just thought of the provided ones over here: SourceForge Link. I have choosen the first .tar.gz package.

Sorry for my english and thanks in advance!

Answer

xboomx picture xboomx · May 13, 2015

Looks like you didn't install SNAP7 library (it's not included in python-snap7)

To use snap7 library on Raspberry Pi with python-snap7 wrapper you need to do followed steps:

  1. Download SNAP7 library for example: snap7-full-1.2.1
    in Pi command line:
    wget http://sourceforge.net/projects/snap7/files/1.2.1/snap7-full-1.2.1.tar.gz/download

  2. Unzip downloaded file
    in Pi command line:
    tar -zxvf snap7-full-1.2.1.tar.gz

  3. Compile library for raspberry (arm_v6_linux.mk is used for RPI 1. For RPI 2 use arm_v7_linux.mk)
    in Pi command line:
    cd snap7-full-1.2.1/build/unix && sudo make -f arm_v6_linux.mk all

  4. Copy compiled library to lib directories
    in Pi command line:
    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

  5. (optional) Install python pip if you don't have it
    in Pi command line:
    sudo apt-get install python-pip

  6. Install python wrapper for SNAP7 lib
    in Pi command line:
    sudo pip install python-snap7