我在Raspberry Pi版本B上运行Rapbian。

我按照此网页上的说明下载了模块python-snap7:Snap7 Installation

我尝试了两次:一次使用pip,另一次手动进行。
但是,我先通过setup.py buildsetup.py install安装了它。

如果我尝试创建客户端,则会出现以下错误:

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

收到此错误后,我进行了以下操作:

我在文件中添加了几行,因此如下所示:
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/

然后我发出命令sudo ldconfig更新缓存文件/etc/ld.so.cache,但错误仍然存​​在:(
  • 在每行的fornt中添加include指令对吗?
  • 我是否看不到任何严重错误?
  • 我需要包括哪个库?
    我只是想到这里提供的:SourceForge Link。我选择了第一个.tar.gz软件包。

  • 对不起,我的英语,谢谢!

    最佳答案

    好像您没有安装SNAP7库(python-snap7中未包含该库)

    要将Raspberry Pi上的snap7库与python-snap7包装器一起使用,您需要执行以下步骤:

  • 下载SNAP7库
    例如:snap7-full-1.2.1在Pi命令行中:wget http://sourceforge.net/projects/snap7/files/1.2.1/snap7-full-1.2.1.tar.gz/download
  • 解压下载的文件
    在Pi命令行中:tar -zxvf snap7-full-1.2.1.tar.gz
  • 用于树莓派的编译库(arm_v6_linux.mk用于RPI1。对于RPI 2,使用arm_v7_linux.mk)
    在Pi命令行中:cd snap7-full-1.2.1/build/unix && sudo make -f arm_v6_linux.mk all
  • 将编译的库复制到lib目录
    在Pi命令行中:sudo cp ../bin/arm_v6-linux/libsnap7.so /usr/lib/libsnap7.sosudo cp ../bin/arm_v6-linux/libsnap7.so /usr/local/lib/libsnap7.so
  • (可选)如果没有,请安装python pip
    在Pi命令行中:sudo apt-get install python-pip
  • 为SNAP7 lib安装python包装器
    在Pi命令行中:sudo pip install python-snap7
  • 09-25 17:42