1

I bought raspberry pi camera and it works, but when i use python to use the camera return Error: cannot import name picamera. I have install python3-picamera.and this is python programming:

from picamera import PiCamera
import time
camera = PiCamera() 
camera.start_preview()
time.sleep(10)
camera.capture('/home/pi/image.jpg')
camera.stop_preview()
  • Could you please edit to include the full error message/stack trace? Thanks. – Aurora0001 Apr 25 '18 at 15:27
3

Methinks too many picamera's. :) Try this instead:

#!/usr/bin/python

import picamera
import time

with picamera.PiCamera() as camera:
   camera.resolution = (640, 480)
   camera.start_preview()
   time.sleep(10)
   camera.capture('/home/pi/image.jpg')
   camera.stop_preview()
| improve this answer | |
2

For anyone else that have the same issue, make sure you didn't create any file named picamera.py. If you did, then the import will try to reference your file instead of the package.

I fixed it by changing the file name from PiCamera.py and delete anything in the directory that was called PiCamera.*

| improve this answer | |
  • I don't see a fine named PiCamera in the question. – Dmitry Grigoryev May 21 '19 at 12:41
  • yeah, im just assuming that, because i have exactly the same code from some online tutorial – abudabid Jun 14 '19 at 10:57
  • naming your first file picamera is a pretty easy mistake to make (I made it too, lol) – Zain Rizvi Jun 13 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.