【问题标题】:How to use OpenCV with Repl.it如何在 Repl.it 中使用 OpenCV
【发布时间】:2019-07-13 02:28:10
【问题描述】:

我想在 Repl.it 中编写 Python 脚本,但我似乎无法导入 OpenCV。我是第一次使用 Repl.it,所以我不确定我应该做什么。

这是我尝试过的不同方法:

  • 只是有
将 opencv_python 导入为 cv2

在 main.py 中会产生以下控制台输出:

Python 3.6.1 (default, Dec 2015, 13:05:11)
[GCC 4.8.2] on linux

Repl.it: Installing fresh packages
Repl.it:

Collecting opencv_python
  Using cached https://files.pythonhosted.org/packages/37/49/874d119948a5a084a7ebe98308214098ef3471d76ab74200f9800efeef15/opencv_python-4.0.0.21-cp36-cp36m-manylinux1_x86_64.whl
Collecting numpy>=1.11.3 (from opencv_python)
  Using cached https://files.pythonhosted.org/packages/f5/bf/4981bcbee43934f0adb8f764a1e70ab0ee5a448f6505bd04a87a2fda2a8b/numpy-1.16.1-cp36-cp36m-manylinux1_x86_64.whl
Installing collected packages: numpy, opencv-python
Successfully installed numpy-1.16.1 opencv-python-4.0.0.21
Target directory /home/runner/.site-packages/numpy-1.16.1.dist-info already exists. Specify --upgrade to force replacement.
Target directory /home/runner/.site-packages/numpy already exists. Specify --upgrade to force replacement.
Target directory /home/runner/.site-packages/opencv_python-4.0.0.21.dist-info already exists. Specify --upgrade to force replacement.
Target directory /home/runner/.site-packages/cv2 already exists. Specify --upgrade to force replacement.
You are using pip version 9.0.1, however version 19.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

Repl.it: package installation success

Traceback (most recent call last):
  File "main.py", line 1, in <module>
    import opencv_python as cv2
ModuleNotFoundError: No module named 'opencv_python'

好像安装正确,但是由于某种原因无法导入...?

  • 我还尝试添加 requirements.txt 文件:
opencv-python==4.0.0.21

但这会产生类似的输出:

Python 3.6.1 (default, Dec 2015, 13:05:11)
[GCC 4.8.2] on linux

Repl.it: Installing fresh packages
Repl.it:

Collecting opencv-python==4.0.0.21 (from -r requirements.txt (line 1))
  Using cached https://files.pythonhosted.org/packages/37/49/874d119948a5a084a7ebe98308214098ef3471d76ab74200f9800efeef15/opencv_python-4.0.0.21-cp36-cp36m-manylinux1_x86_64.whl
Collecting numpy>=1.11.3 (from opencv-python==4.0.0.21->-r requirements.txt (line 1))
  Using cached https://files.pythonhosted.org/packages/f5/bf/4981bcbee43934f0adb8f764a1e70ab0ee5a448f6505bd04a87a2fda2a8b/numpy-1.16.1-cp36-cp36m-manylinux1_x86_64.whl
Installing collected packages: numpy, opencv-python
Successfully installed numpy-1.16.1 opencv-python-4.0.0.21
Target directory /home/runner/.site-packages/numpy-1.16.1.dist-info already exists. Specify --upgrade to force replacement.
Target directory /home/runner/.site-packages/numpy already exists. Specify --upgrade to force replacement.
Target directory /home/runner/.site-packages/opencv_python-4.0.0.21.dist-info already exists. Specify --upgrade to force replacement.
Target directory /home/runner/.site-packages/cv2 already exists. Specify --upgrade to force replacement.
You are using pip version 9.0.1, however version 19.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.


Repl.it: package installation success

Traceback (most recent call last):
  File "main.py", line 1, in <module>
    import opencv_python as cv2
ModuleNotFoundError: No module named 'opencv_python'
  • 我还尝试导入 opencv-python-headless 包(有和没有需求文件),结果相同。

  • 最后,我尝试在 main.py 中使用以下行:

导入简历2

导致此输出:

Python 3.6.1 (default, Dec 2015, 13:05:11)
[GCC 4.8.2] on linux
Traceback (most recent call last):
  File "/run_dir/repl.py", line 60, in <module>
    raise EOFError
EOFError
Traceback (most recent call last):
  File "main.py", line 1, in <module>
    import cv2
  File "/home/runner/.site-packages/cv2/__init__.py", line 3, in <module>
    from .cv2 import *
ImportError: libgthread-2.0.so.0: cannot open shared object file: No such file or directory

我将非常感谢您在导入此软件包方面的任何帮助!

【问题讨论】:

    标签: python opencv import repl.it


    【解决方案1】:

    您可以使用 repl.it 包管理器执行此操作。通过按左侧的立方体图标来执行此操作。

    然后,输入所需的包。

    最后,按下加号按钮。

    要导入opencv-python,请使用

    import cv2  # When installed opencv-python is already "cv2"
    

    【讨论】:

    • # 安装时 opencv-python 已经是 "cv2" - 这说明了很多!
    猜你喜欢
    • 1970-01-01
    • 2021-09-21
    • 2020-04-01
    • 2018-11-16
    • 2020-06-23
    • 2021-06-24
    • 2021-10-03
    • 2013-06-14
    • 2011-06-29
    相关资源
    最近更新 更多