简体   繁体   中英

AttributeError: 'module' object has no attribute 'picamera'

I'm climbing the learning curve with my kids using a project involving rabbits (original project: hamster cam, http://www.raspberrypi.org/learning/hamster-party-cam/worksheet.md ). We've followed the instructions to arrive at the program below.

When we run it, it gives this rather vague error:

Traceback (most recent call last):
   File "/home/pi/hkop.py", line 12, in <module>
     with picamera.picamera() as camera:
AttributeError: 'module' object has no attribute 'picamera'

Can anyone help us resolve this?

import pibrella, picamera, time, random, os, sys

colours = [pibrella.light.red, pibrella.light.amber, pibrella.light.green]

def disco():
    for i in range(25):
        result = random.choice(colours)
        result.on
        time.sleep(0.2)
        result.off()

with picamera.picamera() as camera:
    camera.resolution = (1024, 768)
    pic= 1
    while True:
       if pibrella.input.a.read():
       camera.capture ('/home/pi/konijn/image%03d.jpg' % pic)
       print("Hoera!")
       os.system ('omxplayer 1-39-gcn-dk-mountain.mp3 &')
       disco()
       time.sleep(20)
       pic += 1
       time.sleep(0.01)

From the docs , the class is picamera.PiCamera . So, your with line should be:

with picamera.PiCamera() as camera:
    ...

Also, as Padraic Cunningham pointed out, in your disco() function, the line

result.on

should actually be

result.on()

as you're calling a function of the result object.

picamera.PiCamera() 

not:

picamera.piCamera()

and you should use:

subprocess.Popen

instead of :

os.system

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM