简体   繁体   English

在 Thonny 的 Raspberry Pi 4b 上运行 python 文件时出错

[英]Error when running python file on my Raspberry Pi 4b in Thonny

I am making a remote viewable camera with my Raspberry Pi 4b.我正在用我的 Raspberry Pi 4b 制作远程可视相机。 I am following this tutorial: https://youtu.be/zfBHD4v8hD0?t=705我正在关注本教程: https ://youtu.be/zfBHD4v8hD0?t=705

I am 11:45 into the tutorial, but when I click the run button, I get the following error:我在 11:45 进入教程,但是当我单击运行按钮时,出现以下错误:

RuntimeError: module compiled against API version 0xf but this version of numpy is 0xd
Traceback (most recent call last):
File "/home/pi/pi-camera-stream-flask/main.py", line 7, in <module>
from camera import VideoCamera
File "/home/pi/pi-camera-stream-flask/camera.py", line 5, in <module>
import cv2 as cv
File "/usr/local/lib/python3.9/dist-packages/cv2/__init__.py", line 181, in <module>
bootstrap()
File "/usr/local/lib/python3.9/dist-packages/cv2/__init__.py", line 153, in bootstrap
native_module = importlib.import_module("cv2")
File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: numpy.core.multiarray failed to import

I'm new to RPI, and I have no idea what this error means, or how to fix it.我是 RPI 的新手,我不知道这个错误是什么意思,或者如何解决它。

I tried running我试着跑步

sudo apt-get install VideoCamera

and

sudo apt-get install camera

But it says that it cannot find the file.但它说它找不到该文件。

EDIT: I ran pip install numpy --upgrade as suggested by userid42 And now I get the following error:编辑:我按照 userid42 的建议运行pip install numpy --upgrade userid42现在我收到以下错误:

Traceback (most recent call last):
File "/home/pi/pi-camera-stream-flask/main.py", line 7, in <module>
from camera import VideoCamera
File "/home/pi/pi-camera-stream-flask/camera.py", line 6, in 
<module>
from imutils.video.pivideostream import PiVideoStream
ModuleNotFoundError: No module named 'imutils'

EDIT: Thanks to userid42 running the following fixed it:编辑:感谢userid42运行以下修复它:

pip install numpy --upgrade
pip install imutils

Now when I manually run the script in Thonny, it works, and I am able to view the camera live from any device that is connected to the same WIFI network.现在,当我在 Thonny 中手动运行脚本时,它可以工作,并且我可以从连接到同一 WIFI 网络的任何设备实时查看摄像机。

Now I am trying to have the script run automatically when my RPI 4b is turned on .现在我试图让脚本在我的 RPI 4b 打开时自动运行

I tried the method shown in the video, and also the first two methods here: https://www.dexterindustries.com/howto/run-a-program-on-your-raspberry-pi-at-startup/我尝试了视频中显示的方法,以及这里的前两种方法: https ://www.dexterindustries.com/howto/run-a-program-on-your-raspberry-pi-at-startup/

All three of these methods return the same error I was having to begin with.所有这三种方法都返回我必须开始的相同错误。 This is weird because it works fine when I run it manually, but it gives the error when it runs automatically (on startup).这很奇怪,因为当我手动运行它时它工作正常,但是当它自动运行时(在启动时)它会给出错误。

"Runtimeerror" is complaining about the version of numpy. “Runtimeerror”是在抱怨 numpy 的版本。

Try the following:尝试以下操作:

pip install numpy --upgrade

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

相关问题 Raspberry Pi 4B,启动时使用串口运行 Python 脚本 - Raspberry Pi 4B, running Python Script using serial at boot 在 Python 应用程序中使用 Raspberry Pi 4B 终端命令 - Use Raspberry Pi 4B Terminal Command in Python Application 无法在 Raspberry Pi 4B 上导入 librosa - cannot import librosa on Raspberry Pi 4B 如何使用 opencv-python 代码在树莓派 4b 上使用 MJPG 而不是 YUYV 录制视频 - How can I record a video with MJPG instead of YUYV on a raspberry PI 4b with opencv-python code 我可以在 Raspberry pi 4B 上使用 CircuitPython countio 库吗? - Can I use CircuitPython countio library on Raspberry pi 4B? Raspberry Pi python 代码从 Thonny IDE 运行,但不从终端运行 - Raspberry Pi python code running from Thonny IDE but does not run from the terminal 当我尝试运行此脚本时,出现错误:OverflowError: unsigned short is greater than maximum。 树莓派 4B,传感器为 DHT11 - When i try to run this script, i get a error: OverflowError: unsigned short is greater than maximum. Raspberry pi 4B, the sensor is DHT11 如何将 Raspberry Pi 4B 设置为 I2C 从设备 - How to set up Raspberry Pi 4B as a I2C slave gpiozero.exc.PinPWMUnsupported:引脚 GPIO7 (Raspberry Pi 4B) 不支持 PWM - gpiozero.exc.PinPWMUnsupported: PWM is not supported on pin GPIO7 (Raspberry Pi 4B) Python 4b网关 - Python 4b gateway
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM