Python # Snap7 Libray Import problem

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 image.png

Recommended Posts

Python # Snap7 Libray Import problem
Python module import
Import python script
Summarize Python import
python original module import
Import tsv with Python
How Python module import works
ABC163 C problem with python3
[Python] Dynamic programming knapsack problem
Dynamically import scripts in Python
Import vtk with brew python
[Python] Another way to import
ambisonics simulation (external problem) Python
ABC188 C problem with python3
ABC187 C problem with python
[Python] Solving the import problem due to the difference in entry points
Easy way to customize Python import
[Python] The stumbling block of import
[Note] Project Euler in Python (Problem 1-22)
Working with LibreOffice in Python: import
python> link> from __future__ import absolute_import
ABC166 in Python A ~ C problem
python> Exit processing> import sys / sys.exit ()
About Python, from and import, as
[Python] How to import the library
[Lambda] Make import requests available [python]
[High school mathematics + python] Logarithmic problem
Load Mac Python import MySQL db
Python import directory order (on anaconda)
AtCoder Beginner Contest 174 C Problem (Python)