0

I am trying to use python with my Raspberry Pi 3 to toggle some LED lights I have using openHAB. The problem is when I try to run the python code I get an error and can't figure out what the cause it.

My python is

from openhab import openHAB

base_url = 'http://<ip>:8080/rest'

items = openhab.fetch_all_items()

print("Finished")

When I run the code I it says

Traceback (most recent call last):
File "/home/pi/Desktop/Test.py", line 1, in <module>
from openhab import openHAB
ImportError: No module named 'openhab'

When I use python 2.7 I get this error

Traceback (most recent call last): File "/home/pi/Desktop/Test.py", line 1, in from openhab import openHAB File "/home/pi/.local/lib/python2.7/site-packages/openhab/init.py", line 1, in from .client import openHAB, OpenHAB File "/home/pi/.local/lib/python2.7/site-packages/openhab/client.py", line 40 def init(self, base_url: str, ^ SyntaxError: invalid syntax

I've tried searching google but can't find any solutions that have worked for me.

I have installed openHAB and Python openHAB on my Raspberry Pi.

Dan
  • 1,100
  • 2
  • 13
  • 36
  • Make sure that the copy of Python that you installed Python openHAB into is the same one that you're using to run your code. Having two versions of Python is the only explanation I can think of for the behavior you're describing. So make sure that if you install with /xxx/yyy/bin/pip, you're running your code with /xxx/yyy/bin/python. – CryptoFool Mar 21 '19 at 04:50
  • @Steve I tried using Python 2.7 and got the error I edited into the question. (I didn't know where to figure out what python versions they were so I downgraded to the next version on the pi) – Dan Mar 21 '19 at 05:13
  • My suggestion might still apply. You think you know you're using a specific "Python 2.7" for all operations. Are you sure you only have a single version of Python on your Pi? Maybe you do. I'm just suggesting that you make sure. Sometimes a programmer doesn't realize he has two versions of Python involved, and this sort of problem results. It's not the versions involved. It's simply that you're installing a package into one Python installation, but running with a different one. – CryptoFool Mar 21 '19 at 05:23
  • @Steve According to the Python-openHAB it requires "python >= 3.5" I'm using the Python 3.5.3 Shell to run the code. – Dan Mar 21 '19 at 05:42

0 Answers0