简体   繁体   English

在 Raspberry Pi 上安装 OpenCV 的问题

[英]Problems with OpenCV install on Raspberry Pi

I have a Raspberry Pi running Raspian 10. I installed OpenCV using this tutorial.我有一个运行 Raspian 10 的 Raspberry Pi。我使用教程安装了 OpenCV。 The steps seemed to all complete successfully, but I've had some problems importing the python module.这些步骤似乎都成功完成了,但是我在导入 python 模块时遇到了一些问题。 When I use Python 3.7.3, I get the following output:当我使用 Python 3.7.3 时,我得到以下输出:

>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'

Which is clearly not working.这显然是行不通的。 Using Python 2.7.16 however, it runs fine:然而,使用 Python 2.7.16,它运行良好:

>>> import cv2
>>> cv2.__version__
'4.6.0-dev'

Any idea why this may be?知道为什么会这样吗? It seems like the OpenCV Python module isn't installed globally for Python 3. Ideally, I'd like to be able to use it in a Python 3 virtual environment.似乎没有为 Python 3 全局安装 OpenCV Python 模块。理想情况下,我希望能够在 Python 3 虚拟环境中使用它。

I do have a temporary workaround.我确实有一个临时的解决方法。 If I cd into the build directory containing the module, I can get it to work:如果我cd进入包含模块的构建目录,我可以让它工作:

pi@raspberrypi:~ $ cd opencv/build/python_loader/
pi@raspberrypi:~/opencv/build/python_loader $ ls
cv2  setup.py
pi@raspberrypi:~/opencv/build/python_loader $ python3
Python 3.7.3 (default, Jan 22 2021, 20:04:44) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'4.6.0-dev'

Obviously, this isn't ideal.显然,这并不理想。

I've managed to answer my own question.我设法回答了我自己的问题。 Running:跑步:

pi@raspberrypi:~/opencv/build $ pip3 install -e python_loader

Installs the package from the folder containing the module.从包含模块的文件夹安装包。 It's not the most elegant solution, and I'd still be interested to see if anyone knows why the original method didn't work.这不是最优雅的解决方案,我仍然有兴趣看看是否有人知道为什么原始方法不起作用。

Hope this can be of some help to someone.希望这可以对某人有所帮助。

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

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