garyns / pigpio-dht

DHT11 Temperature and Humidity Sensor using pigpio
GNU General Public License v3.0
14 stars 6 forks source link

Unable to import module with dash in name #1

Closed iothack closed 4 years ago

iothack commented 4 years ago

Hi,

I'm getting an error when I;m trying your code in my Pi.

I have done the following: pi@rpi:~/bin $ sudo pip3 install pigpio-dht

Here is my code:

pi@rpi:~/bin $ cat dht11-pigpio.py
from pigpio-dit import DHT11
gpio = 23
sensor = DHT11(gpio)
result = sensor.read()
print(result)

Here is the error I am getting:

pi@rpi:~/bin/gpio $ python3 dht11-pigpio.py
  File "dht11-pigpio.py", line 7
    from pigpio-dit import DHT11
               ^
SyntaxError: invalid syntax

Based on info on the link below, it seems I need to do something extra in order to import this module. https://stackoverflow.com/questions/8350853/how-to-import-module-when-module-name-has-a-dash-or-hyphen-in-it

garyns commented 4 years ago

Hi,

This was a type-o in the example found in the README. GitHub and PyPi have been updated.

The import must use a _ not -, for example

from pigpio_dit import DHT11   # use _ not -
gpio = 23
sensor = DHT11(gpio)
result = sensor.read()
print(result)

Update your copy of pigpio-dht by pulling from GitHub, or pip install pigpio-dit --upgrade

garyns commented 4 years ago

Closing.