找不到模块名为'picamera'

8

我按照这个网站 (https://www.pyimagesearch.com/2015/03/30/accessing-the-raspberry-pi-camera-with-opencv-and-python/) 设置我的picamera,但是picamera模块出了问题。我已经安装了picamera模块,而且pip freeze也显示我已经有了1.13版本的picamera。

https://imgur.com/a/3y5b2rO

你可以看到我已经有了picamera 1.13,但是当我尝试运行test_image.py时,它显示“没有名为'picamera'的模块”。

https://imgur.com/a/XMEXwXJ

我已经反复卸载和重新安装多次,但错误仍然存在。我该如何解决这个问题?

test_image.py

# import the necessary packages
from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2

# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
rawCapture = PiRGBArray(camera)

# allow the camera to warmup
time.sleep(0.1)

# grab an image from the camera
camera.capture(rawCapture, format="bgr")
image = rawCapture.array

# display the image on screen and wait for a keypress
cv2.imshow("Image", image)
cv2.waitKey(0)

7
请尝试运行命令pip3 install picamera来安装picamera。 - NutCracker
2
Python有两个主要版本,即Python 2.7和Python 3.x。如果你刚开始学习Python,我认为你应该使用已经发布了大约10-11年的Python 3。所以请确保你运行的是Python3及其小伙伴pip3。因此,在开头使用一个清晰地指明你期望的Python版本的shebang,并检查type pythontype python3type piptype pip3的情况。 - Mark Setchell
@NutCracker 错误仍然存在。 - guner
我应该重置SD卡。在我多次重新安装和更改许多东西后,我对我的树莓派的状态感到困惑。 - guner
7个回答

5

对于Python 3,您只需要尝试以下命令。请记住,您需要在主目录中打开终端。

sudo -H apt install python3-picamera
sudo -H pip3 install --upgrade picamera[array]

如果它起作用,请告诉我!


2
当你运行命令 pip3 install picamera 时,如果你已经安装了picamera,它会显示要求已满足,并提供一个路径。现在将该路径复制并包含在你的程序中,如下所示:

    import sys
    sys.path.append('paste the copied path here')
    from picamera.array import PiRGBArray
    from picamera import PiCamera

1

我遇到了同样的问题,直到我注意到我没有将PiCamera中的c大写。


1

请从以下链接中尝试执行以下命令:https://www.raspberrypi.org/documentation/linux/software/python.md

假设picamera模块的路径出现了问题,请尝试清除并重新安装。

使用以下命令进行清除:

sudo apt purge python3-picamera

首先确保一切都是最新的:

sudo apt update

然后:

sudo apt install python3-picamera

-1
树莓派相机可能无法在Windows上工作,请尝试以下命令,它将解决问题。
执行:
set READTHEDOCS=True

现在执行:

pip install picamera

-1

当我有一个名为picamera.py的文件时,我遇到了同样的问题,所以我将其重命名,但是出现了更多的问题。 我希望对你来说也是一样的,否则这已经超出了我的能力范围。


-2

按照以下步骤安装picamera模块

1. 在Windows上执行:set READTHEDOCS=True

1'. 在基于Unix系统上执行:export READTHEDOCS=True

2. 现在执行:pip install picamera


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接