WebThingsIO / webthing-python

Python implementation of a Web Thing server
Mozilla Public License 2.0
177 stars 37 forks source link

Python3 import not work #83

Closed phiko-misc closed 1 year ago

phiko-misc commented 3 years ago

Hello there I don’t know if it is me. but my code can’t import the webthings library the right way

my code:

from webthing import Property, Value, WebThingServer, SingleThing, Thing
import time

def make_thing():
    print("hey1")
    light = Thing(
    'urn:dev:ops:my-lamp-1234',
    'My Lamp',
    ['OnOffSwitch', 'Light'],
    'A web connected lamp'
    )
    print("hey2")
    light.add_property(
    Property(
        light,
        'on',
        Value(True),
        metadata={
            '@type': 'OnOffProperty',
            'title': 'On/Off',
            'type': 'boolean',
            'description': 'Whether the lamp is turned on',
        }))
    print("hey3")
    light.add_property(

The error code:

Traceback (most recent call last):
  File "wt.py", line 1, in <module>
    from webthing import Property, Value, WebThingServer, SingleThing, Thing
  File "/usr/local/lib/python3.5/dist-packages/webthing/__init__.py", line 6, in <module>
    from .property import Property
  File "/usr/local/lib/python3.5/dist-packages/webthing/property.py", line 4, in <module>
    from jsonschema import validate
  File "/usr/local/lib/python3.5/dist-packages/jsonschema/__init__.py", line 56
    raise AttributeError(f"module {__name__} has no attribute {name}")
                                                                    ^
SyntaxError: invalid syntax
flatsiedatsie commented 3 years ago

Did you install it? Is it in your requirements file?

pip3 install -r /path/to/requirements.txt

Python 3.5 is also quite old.