philha
Posts: 5
Joined: Mon Jun 05, 2017 9:17 pm

Import errors

Mon Jun 05, 2017 9:30 pm

I'm working on a sensing project and have hit an error that I can't resolve. When run from the terminal with ./programname the program works fine - reads and displays the sensor info and terminates correctly. When run from IDLE3 I get the following:
Traceback (most recent call last):
File "/home/pi/Documents/Python Project/simpletest2.py", line 62, in <module>
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
File "/home/pi/Adafruit_Python_DHT/Adafruit_DHT/common.py", line 94, in read_retry
humidity, temperature = read(sensor, pin, platform)
File "/home/pi/Adafruit_Python_DHT/Adafruit_DHT/common.py", line 80, in read
platform = get_platform()
File "/home/pi/Adafruit_Python_DHT/Adafruit_DHT/common.py", line 55, in get_platform
from . import Raspberry_Pi_2
File "/home/pi/Adafruit_Python_DHT/Adafruit_DHT/Raspberry_Pi_2.py", line 22, in <module>
from . import Raspberry_Pi_2_Driver as driver
ImportError: cannot import name 'Raspberry_Pi_2_Driver'

Is this an issue with IDLE3? i've added the path containing the Driver to sys.path. Although i note that it says 'cannot import' rather than 'cannot find'.

its a Pi3 and the sensing code is from Adafruit.

It's not a huge deal because as I say, the program works when run from the terminal, it's just puzzling me why the error is thrown up when working in IDLE3

Thanks

Phil

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Import errors

Tue Jun 06, 2017 5:44 am

the program works when run from the terminal, it's just puzzling me why the error is thrown up when working in IDLE3
It will probably puzzle everyone else unless you post the content of simpletest2.py

But here is a guess that I think matches your description...

Does simpletest2.py begin with a 'shebang' line that invokes python? (Not Python3.)

If so then when run from the shell prompt it will will execute under control of the Python2 interpreter and the version of the library module that it successfully imports will be one installed for use with Python2.

When you try to run it from IDLE3 it will execute under control of the Python3 interpreter, and it seems you have not installed a Python3 version of the library.

If that is the case there are 2 options: install the Python3 version of the library, or use IDLE.

Edit: corrected typo - behind/begin
Last edited by B.Goode on Tue Jun 06, 2017 9:06 am, edited 1 time in total.

philha
Posts: 5
Joined: Mon Jun 05, 2017 9:17 pm

Re: Import errors

Tue Jun 06, 2017 8:48 am

Thanks - your analysis was spot on! Using IDLE works fine. I'm new to the environment so didn't realise that I would need to install libraries for Python3.

Thanks again

Phil

Return to “Automation, sensing and robotics”