seattlegray
Posts: 4
Joined: Tue Nov 28, 2017 7:19 am

Error can't figure out "module 'sense-hat' has not attribute 'SenseHat'

Tue Nov 28, 2017 7:31 am

I'm new to the Pi world, running Pi 3 board with Sense Hat, was working fine one second as I ran a few of the Sense Hat example scripts, then it stopped running scripts and now consistently gives this error for any python script for Sense Hat. Screenshot of the error I'm receiving below. Any help greatly appreciated!

Image of error: https://drive.google.com/open?id=1X3VKS ... g3bIqkziC

Thanks in advance

User avatar
Davespice
Forum Moderator
Forum Moderator
Posts: 1662
Joined: Fri Oct 14, 2011 8:06 pm
Location: The Netherlands
Contact: Twitter

Re: Error can't figure out "module 'sense-hat' has not attribute 'SenseHat'

Tue Nov 28, 2017 9:25 am

Ah, sometimes you get strange behaviour like this if you have a .py file which has the same name as a module.
Can you rename the file /home/pi/Desktop/sensehatscripts/random.py to something else? Like my_random.py and see if that makes any difference?

seattlegray
Posts: 4
Joined: Tue Nov 28, 2017 7:19 am

Re: Error can't figure out "module 'sense-hat' has not attribute 'SenseHat'

Tue Nov 28, 2017 2:52 pm

Thanks @Davespice - renamed it as you recommended and still getting same error - other recommendations? Is there a way to test the Sense HAT board to make sure it's not a hardware issue? On reboot the LED matrix does not light up, but if power is unplugged and then plugged back in, the pi3+SenseHAT LED matrix then displays the rainbow on the matrix during boot, but once booted, the scripts I renamed are still generating this error.

DirkS
Posts: 9038
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Error can't figure out "module 'sense-hat' has not attribute 'SenseHat'

Tue Nov 28, 2017 3:10 pm

Looks like Dave got that slightly wrong. You should look for sense_hat.py (and the same with extension .pyc) instead of random..py

seattlegray
Posts: 4
Joined: Tue Nov 28, 2017 7:19 am

Re: Error can't figure out "module 'sense-hat' has not attribute 'SenseHat'

Tue Nov 28, 2017 4:14 pm

Thanks @DirkS, no dice, still getting same error.

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

Re: Error can't figure out "module 'sense-hat' has not attribute 'SenseHat'

Tue Nov 28, 2017 4:41 pm

seattlegray wrote:
Tue Nov 28, 2017 4:14 pm
Thanks @DirkS, no dice, still getting same error.
Surely, it can't be the same error if you no longer have a script named random.py for it to load?

Can you copy and paste the full error message you are now getting, please?

scotty101
Posts: 3100
Joined: Fri Jun 08, 2012 6:03 pm

Re: Error can't figure out "module 'sense-hat' has not attribute 'SenseHat'

Tue Nov 28, 2017 4:54 pm

To eliminate the possibility that it is a problem with your program, please try the following steps

1. Create a new folder, totally empty called 'test_folder'
2. Save the code below as 'test_me.py'
3. Run the code

Code: Select all

from sense_hat import SenseHat
from time import sleep

sense = SenseHat()

red = (255, 0, 0)

sense.show_letter("L", red)
sleep(1)
Should show a red L on the sense hat.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

seattlegray
Posts: 4
Joined: Tue Nov 28, 2017 7:19 am

Re: Error can't figure out "module 'sense-hat' has not attribute 'SenseHat'

Tue Nov 28, 2017 7:13 pm

@B.Goode - same error even with updated file name ("module 'sense-hat' has no attribute 'SenseHat'). Dump from Shell here:
>>> %Run colourwash.py
Traceback (most recent call last):
File "/home/pi/Desktop/sensehatscripts/colourwash.py", line 3, in <module>
from sense_hat import SenseHat
File "/usr/lib/python3/dist-packages/sense_hat/__init__.py", line 2, in <module>
from .sense_hat import SenseHat, SenseHat as AstroPi
File "/usr/lib/python3/dist-packages/sense_hat/sense_hat.py", line 7, in <module>
import numpy as np
File "/usr/lib/python3/dist-packages/numpy/__init__.py", line 142, in <module>
from . import add_newdocs
File "/usr/lib/python3/dist-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/lib/python3/dist-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/lib/python3/dist-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/lib/python3/dist-packages/numpy/core/__init__.py", line 72, in <module>
from numpy.testing.nosetester import _numpy_tester
File "/usr/lib/python3/dist-packages/numpy/testing/__init__.py", line 12, in <module>
from . import decorators as dec
File "/usr/lib/python3/dist-packages/numpy/testing/decorators.py", line 20, in <module>
from .utils import SkipTest, assert_warns
File "/usr/lib/python3/dist-packages/numpy/testing/utils.py", line 15, in <module>
from tempfile import mkdtemp, mkstemp
File "/usr/lib/python3.5/tempfile.py", line 184, in <module>
from random import Random as _Random
File "/home/pi/Desktop/sensehatscripts/random.py", line 34, in <module>
_sense = sense_hat.SenseHat()
AttributeError: module 'sense_hat' has no attribute 'SenseHat'
>>>

However, @scotty101 following your directions I am now looking at a red L on the Sense HAT matrix and no errors. When I moved a script from my previous folders to the test_folder, it now executes perfectly, no errors. When I try to execute any script, even yours, from my previous folder, it gives the above error (shell dump above).

Image here: https://drive.google.com/open?id=1MZ6DG ... bKVgnPlfWC

Any ideas on the cause, what am I missing, as simple as folder permissions?

Huge kudos for the fast responses and help, great community here!

Cheers

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

Re: Error can't figure out "module 'sense-hat' has not attribute 'SenseHat'

Tue Nov 28, 2017 7:31 pm

Code: Select all

from random import Random as _Random
File "/home/pi/Desktop/sensehatscripts/random.py", line 34, in <module>
_sense = sense_hat.SenseHat()
AttributeError: module 'sense_hat' has no attribute 'SenseHat'
>>> 
That says to me that when your script tries to import random it does so from random.py in your own sensehatscripts directory. But I thought that in response to a previous reply that you had renamed that file? (You will need to delete or rename the corresponding .pyc file as well.)

Disclaimer: I don't have a Sense Hat and have never run the associated software - maybe it deliberately plants its own copy of the module to be loaded..?

scotty101
Posts: 3100
Joined: Fri Jun 08, 2012 6:03 pm

Re: Error can't figure out "module 'sense-hat' has not attribute 'SenseHat'

Tue Nov 28, 2017 9:16 pm

You must have a file called sense_hat in your original folder. Only logical explanation.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

User avatar
Davespice
Forum Moderator
Forum Moderator
Posts: 1662
Joined: Fri Oct 14, 2011 8:06 pm
Location: The Netherlands
Contact: Twitter

Re: Error can't figure out "module 'sense-hat' has not attribute 'SenseHat'

Mon Dec 04, 2017 8:48 am

I might suggest to zip up the whole sensehatscripts folder and put that online for us to look at.

Return to “Astro Pi”

Who is online

Users browsing this forum: No registered users and 4 guests