【问题标题】:How to link python3 to a specific version of opencv?如何将python3链接到特定版本的opencv?
【发布时间】:2021-04-08 10:14:52
【问题描述】:

我成功编译安装了OpenCV 4.5.0,但是用python3导入cv2的时候发现cv2的版本是4.5.1。像下面的输出:

Python 3.6.9 (default, Oct  8 2020, 12:12:24) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> print(cv2.getBuildInformation())

General configuration for OpenCV 4.5.1 =====================================
  Version control:               4.5.1-dirty

  Platform:
    Timestamp:                   2021-01-02T12:47:39Z
    Host:                        Linux 5.4.0-54-generic aarch64
    CMake:                       3.18.4
    CMake generator:             Unix Makefiles
    CMake build tool:            /bin/gmake
    Configuration:               Release

 .........

  Python 3:
    Interpreter:                 /opt/python/cp36-cp36m/bin/python (ver 3.6.12)
    Libraries:                   libpython3.6m.a (ver 3.6.12)
    numpy:                       /tmp/pip-build-env-c03ewnak/overlay/lib/python3.6/site-packages/numpy/core/include (ver 1.19.3)
    install path:                python

  Python (for build):            /bin/python2.7

  Install to:                    /tmp/pip-req-build-zuuo394f/_skbuild/linux-aarch64-3.6/cmake-install
-----------------------------------------------------------------

当我打开/tmp时,我找不到文件夹/pip-req-build-zuuo394f

但是当我使用 python(2.7.17) 时,我得到了正确版本的 opencv:

Python 2.7.17 (default, Sep 30 2020, 13:38:04) 
[GCC 7.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> print(cv2.getBuildInformation())

General configuration for OpenCV 4.5.0 =====================================
  Version control:               unknown

  Extra modules:
    Location (extra):            /home/xana/opencv_contrib/modules
    Version control (extra):     unknown

  Platform:
    Timestamp:                   2021-04-07T04:04:29Z
    Host:                        Linux 4.9.140-tegra aarch64
    CMake:                       3.10.2
    CMake generator:             Unix Makefiles
    CMake build tool:            /usr/bin/make
    Configuration:               RELEASE

.......

  cuDNN:                         YES (ver 8.0.0)

  Python 2:
    Interpreter:                 /usr/bin/python2.7 (ver 2.7.17)
    Libraries:                   /usr/lib/aarch64-linux-gnu/libpython2.7.so (ver 2.7.17)
    numpy:                       /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.13.3)
    install path:                lib/python2.7/dist-packages/cv2/python-2.7

  Python 3:
    Interpreter:                 /usr/bin/python3 (ver 3.6.9)
    Libraries:                   /usr/lib/aarch64-linux-gnu/libpython3.6m.so (ver 3.6.9)
    numpy:                       /usr/lib/python3/dist-packages/numpy/core/include (ver 1.13.3)
    install path:                lib/python3.6/dist-packages/cv2/python-3.6

  Python (for build):            /usr/bin/python2.7

  Install to:                    /usr
-----------------------------------------------------------------

而在 python2 的 cv2 中,cv2 中的所有函数都可以正常工作。 那么如何更改python3中的cv2版本呢?非常感谢!

【问题讨论】:

  • 只需print(cv2) 它会告诉你它从哪里读取模块,我想构建信息是它最初的编译方式
  • @Peter 你的回复解决了我的问题,非常感谢!

标签: python python-3.x opencv


【解决方案1】:

我遵循@Peter 的建议print(cv2)。我在/home/.local/lib/python3.6/site-packages/cv2 文件夹中找到了一个cv2.so,但我的OpenCV 4.5.0 安装在usr/lib/python3.6/dist-packages/cv2 中。

然后,我删除了/home/...中的cv2文件夹,我再次import cv2cv2.__version__现在是4.5.0,所有功能都可以正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-30
    • 2012-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多