gpt4 book ai didi

python - 如何在Repl.it中使用OpenCV

转载 作者:行者123 更新时间:2023-12-02 16:37:24 29 4
gpt4 key购买 nike

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

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

  • 只有
  •     import opencv_python as cv2

    in main.py results in the following console output:

    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

    but this results in a similar output:

    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中使用以下行:
  • import cv2

    which results in this output:

    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

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

    最佳答案

    您可以使用repl.it程序包管理器执行此操作。通过按左侧的多维数据集图标来执行此操作。
    where you can find the cube

    然后,输入所需的包。
    where to enter desired package

    最后,按加号按钮。

    要导入opencv-python,请使用

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

    关于python - 如何在Repl.it中使用OpenCV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54768722/

    29 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com