Ubuntu 分支上的 OpenCV Python 问题 - 跟进

问题描述 投票:0回答:1

设置:尝试在 Ubuntu (22.04.3 LTS) 上使用 Anaconda 3、PyCharm Community Edition (2023.3.2) 和许多现有软件包(包括 opencv-python)进行 python 开发。我遇到了问题中描述的问题

Python OpenCV 错误:当前线程不是对象的线程

但这确实是一个新问题,因为我显然遇到了某种配置问题。简而言之,Python 3 中的 CV2 调用会导致如下所示的错误:

QObject::moveToThread:当前线程()不是对象的线程(0x1e57d70)。 无法移动到目标线程 ()。

似乎对其他人有帮助的推荐解决方案是首先卸载 opencv-python 软件包,然后重新安装它,并使用以下命令在目标平台上重建软件包:

pip install --no-binary opencv-python opencv-python

在尝试此操作时,当我收到无法找到 Python.h 的有点令人难以置信的错误时,构建达到 100%。完整的错误粘贴在下面,但一些背景知识可能会有所帮助。虽然我对 Linux 并不陌生,但对 Ubuntu 有点陌生,而且对开发也比较陌生(更多的是系统工程师而不是软件工程师)。如果这些安装程序(apt、apt-get、pip 等)无法解析依赖项和路径,我将很难弄清楚。 PyCharm 包视图似乎相当不错,它与 conda 的连接似乎还不错(简单的程序可以正常工作),但下面的某些东西是不对的。也许与 gcc 的连接?我感谢所有建议和提供的帮助。预先感谢。

-Rocky714

  Note: Class cv::Feature2D has more than 1 base class (not supported by Python C extensions)
        Bases:  cv::Algorithm, cv::class, cv::Feature2D, cv::Algorithm
        Only the first base class will be used
  Note: Class cv::detail::GraphCutSeamFinder has more than 1 base class (not supported by Python C extensions)
        Bases:  cv::detail::GraphCutSeamFinderBase, cv::detail::SeamFinder
        Only the first base class will be used
  [100%] Built target gen_opencv_python_source
  [100%] Building CXX object modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o
  In file included from /tmp/pip-install-s65xv3yn/opencv-python_f0507c14ed7b488894517f39f468dff8/opencv/modules/python/src2/cv2.cpp:5:
  /tmp/pip-install-s65xv3yn/opencv-python_f0507c14ed7b488894517f39f468dff8/opencv/modules/python/src2/cv2.hpp:20:10: fatal error: Python.h: No such file or directory
     20 | #include <Python.h>
        |          ^~~~~~~~~~
  compilation terminated.
  gmake[2]: *** [modules/python3/CMakeFiles/opencv_python3.dir/build.make:76: modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o] Error 1
  gmake[1]: *** [CMakeFiles/Makefile2:2304: modules/python3/CMakeFiles/opencv_python3.dir/all] Error 2
  gmake: *** [Makefile:166: all] Error 2
  Traceback (most recent call last):
    File "/tmp/pip-build-env-deg9zvgy/overlay/lib/python3.10/site-packages/skbuild/setuptools_wrap.py", line 674, in setup
      cmkr.make(make_args, install_target=cmake_install_target, env=env)
    File "/tmp/pip-build-env-deg9zvgy/overlay/lib/python3.10/site-packages/skbuild/cmaker.py", line 697, in make
      self.make_impl(clargs=clargs, config=config, source_dir=source_dir, install_target=install_target, env=env)
    File "/tmp/pip-build-env-deg9zvgy/overlay/lib/python3.10/site-packages/skbuild/cmaker.py", line 742, in make_impl
      raise SKBuildError(msg)
  
  An error occurred while building with CMake.
    Command:
      /tmp/pip-build-env-deg9zvgy/overlay/lib/python3.10/site-packages/cmake/data/bin/cmake --build . --target install --config Release --
    Install target:
      install
    Source directory:
      /tmp/pip-install-s65xv3yn/opencv-python_f0507c14ed7b488894517f39f468dff8
    Working directory:
      /tmp/pip-install-s65xv3yn/opencv-python_f0507c14ed7b488894517f39f468dff8/_skbuild/linux-x86_64-3.10/cmake-build
  Please check the install target is valid and see CMake's output for more information.
  
  [end of output]

注意:此错误源自子进程,并且可能不是 pip 的问题。 错误:opencv-python 构建轮子失败 无法构建 opencv-python 错误:无法为 opencv-python 构建轮子,这是安装基于 pyproject.toml 的项目所必需的

python opencv ubuntu pycharm anaconda3
1个回答
0
投票

尝试运行此命令

sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev

然后尝试使用apt的pip重新安装opencv

© www.soinside.com 2019 - 2024. All rights reserved.