Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

ImportError: No module named Adafruit_DHT
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

ImportError: No module named Adafruit_DHT

by nashville_bill on Fri Jun 08, 2018 6:03 pm

Hi,

I hope I can get some help with this problem; I've been trying to solve this for two days.

I am trying to use the DHT22 on my Raspberry Pi 3. I have installed the Adafruit_DHT library, and I can get the temp and humidity when testing with from the Terminal window, but I get an error when running my code from Idle Python 3.4.2.

I have installed Adafruit_Python_DHT, and the library, several times.

My code stops and gives the below error when it tries to import AdafruitDHT.

import sys
import time
import datetime
import Adafruit_DHT

Traceback (most recent call last):
File "/home/pi/Desktop/temphumiddb.py, line 7, in <module>
import Adafruit_DHT
ImportError: No module named Adafruit_DHT

* I found another post about this same problem, but I wasn't able to find the answer for my instance.

Thank you in advance.

nashville_bill

nashville_bill
 
Posts: 1
Joined: Wed Mar 02, 2016 7:50 pm

Re: ImportError: No module named Adafruit_DHT

by RedFoxy on Mon Aug 06, 2018 10:09 am

Same issue here!

RedFoxy
 
Posts: 6
Joined: Mon Aug 06, 2018 10:08 am

Re: ImportError: No module named Adafruit_DHT

by adafruit_support_carter on Mon Aug 06, 2018 12:19 pm

Did you install for Python 2 or 3?

adafruit_support_carter
 
Posts: 17282
Joined: Tue Nov 29, 2016 2:45 pm

Re: ImportError: No module named Adafruit_DHT

by RedFoxy on Tue Aug 07, 2018 4:56 am

adafruit_support_carter wrote:Did you install for Python 2 or 3?

I tried to install it by pip and by your source from githuib, I've installed last, and with all updates, debian for raspberry pi 3

Code: Select all | TOGGLE FULL SIZE
~# cat /etc/debian_version
9.4
~# python -V
Python 2.7.13
~# python3 -V
Python 3.5.3
~# pip -V
pip 18.0 from /usr/local/lib/python3.5/dist-packages/pip (python 3.5)
~# updatedb
~# locate Adafruit
/usr/local/lib/python3.5/dist-packages/Adafruit_DHT
/usr/local/lib/python3.5/dist-packages/Adafruit_DHT-1.3.4.dist-info
~# dpkg -l | grep python
ii  dh-python                        2.20170125
ii  libpython-dev:armhf              2.7.13-2
ii  libpython-stdlib:armhf           2.7.13-2
ii  libpython2.7:armhf               2.7.13-2+deb9u2
ii  libpython2.7-dev:armhf           2.7.13-2+deb9u2
ii  libpython2.7-minimal:armhf       2.7.13-2+deb9u2
ii  libpython2.7-stdlib:armhf        2.7.13-2+deb9u2
ii  libpython3-stdlib:armhf          3.5.3-1
ii  libpython3.5:armhf               3.5.3-1
ii  libpython3.5-minimal:armhf       3.5.3-1
ii  libpython3.5-stdlib:armhf        3.5.3-1
ii  python                           2.7.13-2
ii  python-acme                      0.10.2-1
ii  python-apt-common                1.1.0~beta5
ii  python-certbot                   0.10.2-1
ii  python-cffi-backend              1.9.1-2
ii  python-chardet                   2.3.0-2
ii  python-configargparse            0.11.0-1
ii  python-configobj                 5.0.6-2
ii  python-crypto                    2.6.1-7
ii  python-cryptography              1.7.1-3+b2
ii  python-dev                       2.7.13-2
ii  python-dnspython                 1.15.0-1
ii  python-enum34                    1.1.6-1
ii  python-funcsigs                  1.0.2-3
ii  python-idna                      2.2-1
ii  python-ipaddress                 1.0.17-1
ii  python-ldb                       2:1.1.27-1
ii  python-minimal                   2.7.13-2
ii  python-mock                      2.0.0-3
ii  python-openssl                   16.2.0-1
ii  python-parsedatetime             2.1-3
ii  python-pbr                       1.10.0-1
ii  python-pip-whl                   9.0.1-2+rpt2
ii  python-pkg-resources             33.1.1-1
ii  python-psutil                    5.0.1-1
ii  python-pyasn1                    0.1.9-2
ii  python-pyicu                     1.9.5-1
ii  python-requests                  2.12.4-1
ii  python-rfc3339                   1.0-4
ii  python-rpi.gpio                  0.6.3~stretch-1
ii  python-samba                     2:4.5.12+dfsg-2+deb9u2
ii  python-setuptools                33.1.1-1
ii  python-six                       1.10.0-3
ii  python-talloc                    2.1.8-1
ii  python-tdb                       1.3.11-2
ii  python-tz                        2016.7-0.3
ii  python-urllib3                   1.19.1-1
ii  python-zope.component            4.3.0-1
ii  python-zope.event                4.2.0-1
ii  python-zope.hookable             4.0.4-4+b1
ii  python-zope.interface            4.3.2-1
ii  python2.7                        2.7.13-2+deb9u2
ii  python2.7-dev                    2.7.13-2+deb9u2
ii  python2.7-minimal                2.7.13-2+deb9u2
ii  python3                          3.5.3-1
ii  python3-apt                      1.1.0~beta5
ii  python3-minimal                  3.5.3-1
ii  python3-pyinotify                0.9.6-1
ii  python3-systemd                  233-1
ii  python3.5                        3.5.3-1
ii  python3.5-minimal                3.5.3-1

RedFoxy
 
Posts: 6
Joined: Mon Aug 06, 2018 10:08 am

Re: ImportError: No module named Adafruit_DHT

by adafruit_support_carter on Tue Aug 07, 2018 10:17 am

Code: Select all | TOGGLE FULL SIZE
~# python -V
Python 2.7.13
~# python3 -V
Python 3.5.3
~# pip -V
pip 18.0 from /usr/local/lib/python3.5/dist-packages/pip (python 3.5)


On your system, "python" is mapping to Python 2 while "pip" is mapping to Python 3. If you installed using "pip" and then ran using "python", then the library was installed for 3 but you are running 2. Try running the script with Python 3.

adafruit_support_carter
 
Posts: 17282
Joined: Tue Nov 29, 2016 2:45 pm

Re: ImportError: No module named Adafruit_DHT

by RedFoxy on Tue Aug 07, 2018 10:59 am

adafruit_support_carter wrote:On your system, "python" is mapping to Python 2 while "pip" is mapping to Python 3. If you installed using "pip" and then ran using "python", then the library was installed for 3 but you are running 2. Try running the script with Python 3.

Thank you, forcing the install using python2 setup.py install but still Home Assistant doesn't goes with it :|

RedFoxy
 
Posts: 6
Joined: Mon Aug 06, 2018 10:08 am

Re: ImportError: No module named Adafruit_DHT

by RedFoxy on Tue Aug 07, 2018 11:46 am

Code: Select all | TOGGLE FULL SIZE
$ pip3 install Adafruit_Python_DHT==1.3.2 
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting Adafruit_Python_DHT==1.3.2
  Using cached https://files.pythonhosted.org/packages/52/aa/418b82e36fc57316137679c2a12b8bae89ab73f211cbca91a3275e0b5fc2/Adafruit_Python_DHT-1.3.2.tar.gz
Building wheels for collected packages: Adafruit-Python-DHT
  Running setup.py bdist_wheel for Adafruit-Python-DHT ... error
  Complete output from command /srv/homeassistant/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-eo4f544r/Adafruit-Python-DHT/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-iofnbwfr --python-tag cp35:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-armv7l-3.5
  creating build/lib.linux-armv7l-3.5/Adafruit_DHT
  copying Adafruit_DHT/Raspberry_Pi_2.py -> build/lib.linux-armv7l-3.5/Adafruit_DHT
  copying Adafruit_DHT/Test.py -> build/lib.linux-armv7l-3.5/Adafruit_DHT
  copying Adafruit_DHT/common.py -> build/lib.linux-armv7l-3.5/Adafruit_DHT
  copying Adafruit_DHT/Beaglebone_Black.py -> build/lib.linux-armv7l-3.5/Adafruit_DHT
  copying Adafruit_DHT/__init__.py -> build/lib.linux-armv7l-3.5/Adafruit_DHT
  copying Adafruit_DHT/platform_detect.py -> build/lib.linux-armv7l-3.5/Adafruit_DHT
  copying Adafruit_DHT/Raspberry_Pi.py -> build/lib.linux-armv7l-3.5/Adafruit_DHT
  running build_ext
  building 'Adafruit_DHT.Raspberry_Pi_2_Driver' extension
  creating build/temp.linux-armv7l-3.5
  creating build/temp.linux-armv7l-3.5/source
  creating build/temp.linux-armv7l-3.5/source/Raspberry_Pi_2
  arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.5-RUbMX3/python3.5-3.5.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/srv/homeassistant/include -I/usr/include/python3.5m -c source/_Raspberry_Pi_2_Driver.c -o build/temp.linux-armv7l-3.5/source/_Raspberry_Pi_2_Driver.o -std=gnu99
  arm-linux-gnueabihf-gcc: error: source/_Raspberry_Pi_2_Driver.c: File o directory non esistente
  arm-linux-gnueabihf-gcc: fatal error: no input files
  compilation terminated.
  error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
 
  ----------------------------------------
  Failed building wheel for Adafruit-Python-DHT
  Running setup.py clean for Adafruit-Python-DHT
Failed to build Adafruit-Python-DHT
Installing collected packages: Adafruit-Python-DHT
  Running setup.py install for Adafruit-Python-DHT ... error
    Complete output from command /srv/homeassistant/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-eo4f544r/Adafruit-Python-DHT/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-ecip7fq5/install-record.txt --single-version-externally-managed --compile --install-headers /srv/homeassistant/include/site/python3.5/Adafruit-Python-DHT:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-armv7l-3.5
    creating build/lib.linux-armv7l-3.5/Adafruit_DHT
    copying Adafruit_DHT/Raspberry_Pi_2.py -> build/lib.linux-armv7l-3.5/Adafruit_DHT
    copying Adafruit_DHT/Test.py -> build/lib.linux-armv7l-3.5/Adafruit_DHT
    copying Adafruit_DHT/common.py -> build/lib.linux-armv7l-3.5/Adafruit_DHT
    copying Adafruit_DHT/Beaglebone_Black.py -> build/lib.linux-armv7l-3.5/Adafruit_DHT
    copying Adafruit_DHT/__init__.py -> build/lib.linux-armv7l-3.5/Adafruit_DHT
    copying Adafruit_DHT/platform_detect.py -> build/lib.linux-armv7l-3.5/Adafruit_DHT
    copying Adafruit_DHT/Raspberry_Pi.py -> build/lib.linux-armv7l-3.5/Adafruit_DHT
    running build_ext
    building 'Adafruit_DHT.Raspberry_Pi_2_Driver' extension
    creating build/temp.linux-armv7l-3.5
    creating build/temp.linux-armv7l-3.5/source
    creating build/temp.linux-armv7l-3.5/source/Raspberry_Pi_2
    arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.5-RUbMX3/python3.5-3.5.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/srv/homeassistant/include -I/usr/include/python3.5m -c source/_Raspberry_Pi_2_Driver.c -o build/temp.linux-armv7l-3.5/source/_Raspberry_Pi_2_Driver.o -std=gnu99
    arm-linux-gnueabihf-gcc: error: source/_Raspberry_Pi_2_Driver.c: File o directory non esistente
    arm-linux-gnueabihf-gcc: fatal error: no input files
    compilation terminated.
    error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
   
    ----------------------------------------
Command "/srv/homeassistant/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-eo4f544r/Adafruit-Python-DHT/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-ecip7fq5/install-record.txt --single-version-externally-managed --compile --install-headers /srv/homeassistant/include/site/python3.5/Adafruit-Python-DHT" failed with error code 1 in /tmp/pip-install-eo4f544r/Adafruit-Python-DHT/

RedFoxy
 
Posts: 6
Joined: Mon Aug 06, 2018 10:08 am

Re: ImportError: No module named Adafruit_DHT

by RedFoxy on Tue Aug 07, 2018 12:09 pm

ok, no comment... now installing AdaFruit_Python_DHT using pip3 it goes...

RedFoxy
 
Posts: 6
Joined: Mon Aug 06, 2018 10:08 am

Re: ImportError: No module named Adafruit_DHT

by adafruit_support_carter on Tue Aug 07, 2018 3:54 pm

Just ran through the install instructions on a Pi and it seemed to work for me:
Code: Select all | TOGGLE FULL SIZE
pi@raspberrypi:~ $ sudo pip3 install Adafruit_DHT
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting Adafruit_DHT
  Downloading https://www.piwheels.org/simple/adafruit-dht/Adafruit_DHT-1.3.4-cp35-cp35m-linux_armv6l.whl
Installing collected packages: Adafruit-DHT
Successfully installed Adafruit-DHT-1.3.4
pi@raspberrypi:~ $


Try again. Maybe you missed a step? I used the readme from here:
https://github.com/adafruit/Adafruit_Python_DHT
I'm only showing the last step, but I ran them all (for Python 3).

adafruit_support_carter
 
Posts: 17282
Joined: Tue Nov 29, 2016 2:45 pm

Re: ImportError: No module named Adafruit_DHT

by RedFoxy on Wed Aug 08, 2018 3:45 am

I solve it but I don't believe it too much... Frist I installed pip2 than I installed Adafruit_DHT by pip2, so my temeperatura_rack.py goes, than I tried to use Home Assistant but it use python3, so I installed adafruti by pip3 but nothing, Home Assistant doesn't found it and it was looking for 1.3.2 version, so I tried to install it by pip3 but it fail for troubles with wheel, I tried to upgrade and that to uninstall and install again wheel but nothing, so I look for 1.3.2 source but I don't find it, than I tried to install 1.3.3 again and... it goes! Than I tried to upgrade to 1.3.4 and it goes too...

For my script temeperatura_rack.py , after adding () to print it goes now

RedFoxy
 
Posts: 6
Joined: Mon Aug 06, 2018 10:08 am

Re: ImportError: No module named Adafruit_DHT

by JohnUK on Tue Aug 14, 2018 1:28 pm

adafruit_support_carter wrote:
Code: Select all | TOGGLE FULL SIZE
~# python -V
Python 2.7.13
~# python3 -V
Python 3.5.3
~# pip -V
pip 18.0 from /usr/local/lib/python3.5/dist-packages/pip (python 3.5)


On your system, "python" is mapping to Python 2 while "pip" is mapping to Python 3. If you installed using "pip" and then ran using "python", then the library was installed for 3 but you are running 2. Try running the script with Python 3.


I had this situation too (wrong Python version). To change to Python version 3.5 I used this approach:
https://linuxconfig.org/how-to-change-f ... bian-linux

I then re-ran setup.py in Adafruit_Python_DHT (not sure if this was necessary, but it seemed like a good idea).

It worked! The ImportError problem then went away when using both Idle3 and Thonny.

JohnUK
 
Posts: 1
Joined: Tue Aug 14, 2018 1:16 pm

Please be positive and constructive with your questions and comments.