Search code examples
pythonopc-ua

python freeopcua import error: cannot import name Client


folks, i got python 3.5.0 installed on a windows 7 machine and used pip3 to install dependencies cryptography, dateutil, lxml and pytz as mentioned on the freeopcua homepage. thereafter I installed freeopcua using pip3 as well.

when trying to run one of the examples https://github.com/FreeOpcUa/python-opcua/blob/master/examples/client_to_kepware.py I got the error 1 import sys 2 sys.path.insert(0, "..") 3 import logging 4 5 from opcua import Client 6 from opcua import uaprotocol as ua

"Traceback (most recent call last): File "xxx\Desktop\opcua.py", line 5, in from opcua import Client File "xxx\Desktop\opcua.py", line 5, in from opcua import Client ImportError: cannot import name 'Client'"

in my directory "xxx\Python35-32\Lib\site-packages" I do see opcua and freeopcua-0.09.3-py3.5.egg-info so it appears to be intalled correctly. inside opcua package there is a __init__ importing from opcua.client.client import Client from a folder client that exists on the same level as __init__. that folder has a module client.py and that module is holding class "Client". so to me everything appears fine but I am not very experienced here.

Not sure what is causing this? thanks for help!


Solution

  • above issue did take me quite some time and after being stuck for one evening I decided to ask. However, I eductated myself on packages that morning and appears like sys.path(0..) is the reason. Not 100% sure why it is used but it somehow changes directory. After puting file into my Python directory /Pyton35-32 it is working