简体   繁体   English

没有名为“picamera”的模块

[英]No module named ‘picamera'

I followed this website ( https://www.pyimagesearch.com/2015/03/30/accessing-the-raspberry-pi-camera-with-opencv-and-python/ ) to set my picamera, but I have a problem with the picamera module.我跟着这个网站( https://www.pyimagesearch.com/2015/03/30/accessing-the-raspberry-pi-camera-with-opencv-and-python/ )来设置我的picamera,但我有一个问题使用 picamera 模块。 I did install the picamera module, and this picture is from pip freeze.我确实安装了 picamera 模块,这张图片来自 pip freeze。

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

You can see I have picamera 1.13 already, but when I try test_image.py, it says "No module named 'picamera'".你可以看到我已经有 picamera 1.13,但是当我尝试 test_image.py 时,它说“没有名为‘picamera’的模块”。

https://imgur.com/a/XMEXwXJ https://imgur.com/a/XMEXwXJ

I have uninstalled and installed many times, but the error still exist.我已经卸载并安装了很多次,但错误仍然存​​在。 How do I fix this?我该如何解决?

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)

for python3 you have to just try this below commands.keep in mind that you need to open terminal in home directory.对于python3,您必须在下面的命令中尝试此操作。请记住,您需要在主目录中打开终端。

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

let me know if it works!让我知道它是否有效!

When you run the command pip3 install picamera , it will show that the requirement is already satisfied followed by a path , provided if you have already installed picamera.当您运行命令pip3 install picamera 时,它会显示要求已经满足,后跟路径,如果您已经安装了 picamera。 Now copy that path and include it in your program as follows:现在复制该路径并将其包含在您的程序中,如下所示:

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

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

Try the following commands from: https://www.raspberrypi.org/documentation/linux/software/python.md尝试以下命令: https : //www.raspberrypi.org/documentation/linux/software/python.md

I'm assuming the path for the picamera module is messed up for some reason, so try purging it and reinstalling it.我假设 picamera 模块的路径由于某种原因搞砸了,所以尝试清除它并重新安装它。

Purge using:清除使用:

sudo apt purge python3-picamera

First make sure everything is up to date:首先确保一切都是最新的:

sudo apt update

Then:然后:

sudo apt install python3-picamera

使用以下步骤安装 picamera 模块

1.On Windows, execute: set READTHEDOCS=True

1'.On Unix based systems, execute: export READTHEDOCS=True

2.Now execute: pip install picamera

Pi camera may not work on windows try following commands, it will resolve issue Pi 相机可能无法在 Windows 上运行尝试以下命令,它将解决问题

execute:执行:

set READTHEDOCS=True

Now execute:现在执行:

pip install picamera

When I had a file named picamera.py, I had the same problem so I renamed it and since more problem.当我有一个名为 picamera.py 的文件时,我遇到了同样的问题,所以我重命名了它,因为更多的问题。 I hope it's the same for you, otherwise it's above my skills.我希望它对你来说也是一样,否则它超出了我的技能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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