can't find snap7 library - linux

和自甴很熟 提交于 2019-12-10 10:47:12

问题


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!


回答1:


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




回答2:


You have not installed snap7 library that is why you have this problem.

In order to solve this problem I suggest you to install it in a proper way. What I describe below is a horrible hacky way, but I have not found time to make better.

For a quick fix you can

  • download this: http://sourceforge.net/projects/snap7/files/1.1.0/
  • unar it, and
  • in folder 'build/unix'
  • run command make -f x86_64_linux.mk all
  • then cp ../../build/bin/x86_64_linux /usr/local/lib/
  • then modify common.py in order to manually point to your '.so' file in 'init' function

I added this line at start of this function : lib_location = "/usr/local/lib/libsnap7.so"




回答3:


I got a solution:

sudo chown -R $USER /usr/local/lib/python2.7/dist-packages/snap7

To give permissions to edit files in the snap7 library directory.

Then edit the complaining files, below the init with an additional line like this:

def __init__(self):
    lib_location='/usr/local/lib/libsnap7.so' # add this line here


来源:https://stackoverflow.com/questions/24343557/cant-find-snap7-library-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!