2

Having problem in bootstrapping my OBD scanner using python-obd library. I'm more of a Ruby guy, new to python. Doing the python-obd's tutorial code and terminal answers this:

 File "car.py", line 2, in <module>
    import obd
  File "/Users/aabulkhairov/Development/publicobd/obd.py", line 3, in     <module>
AttributeError: 'module' object has no attribute 'OBD'

Do i have to find the obd.py file and copy it to this file's folder?

Here's the car.py:

import obd

connection = obd.OBD() # auto-connects to USB or RF port

cmd = obd.commands.SPEED # select an OBD command (sensor)

response = connection.query(cmd) # send the command, and parse the response

print(response.value) # returns unit-bearing values thanks to Pint
print(response.value.to("mph")) # user-friendly unit conversions
aabulkhairov
  • 366
  • 2
  • 9
  • "Do i have to find the obd.py file and copy it to this file's folder?" No and since your import works then I'm guessing you correctly installed with `pip`? You didn't call one of your own files `obd.py` did you? – roganjosh Mar 01 '17 at 15:11
  • Yeah, i correctly did "pip install obd" and it went fine. Also no, i have only one file named "car.py" in my working directory – aabulkhairov Mar 01 '17 at 15:40
  • 1
    Oh i found issue :) At first i called file "obd.py" then renamed to "car.py". But the file "obd.pyc" was generated - removed it and script worked fine! Thanks – aabulkhairov Mar 01 '17 at 15:42

1 Answers1

4

One thing I learned is that you shouldn't name your (test) Python file:

obd.py

And then start with a search of the available ports:

ports = obd.scan_serial()      # return list of valid USB or RF ports
Wallem89
  • 304
  • 2
  • 14