从源代码构建的OpenCV:Pycharm无法获取自动完成信息 [英] OpenCV built from source: Pycharm doesn't get autocomplete information

查看:195
本文介绍了从源代码构建的OpenCV:Pycharm无法获取自动完成信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将OpenCV安装到我的python环境(Windows)中,并且几乎已经完成了所有工作,但是在自动完成和Pycharm本身导入库方面仍然存在一些问题.我经历了无数其他相关主题,但似乎其中大多数主题要么已经过时,要么是预构建版本,要么没有答案.

I'm trying to install OpenCV into my python environment (Windows), and I'm almost all of the way there, but still having some issues with autocomplete and Pycharm itself importing the library. I've been through countless other related threads, but it seems like most of them are either outdated, for prebuilt versions, or unanswered.

我正在使用Anaconda,并且有多个环境,但是不幸的是,通过pip install opencv-contrib-python安装它并没有包含我需要的一切.因此,我是从源代码构建的,并且库本身似乎运行良好.构建过程将一些东西安装到./Anaconda3/envs/cv/Lib/site-packages/cv2/中:__init__.py,一些config py文件和.../cv2/python-3.8/cv2.cp38-win_amd64.pyd.我不确定它是否还有其他用途.

I'm using Anaconda and have several environments, and unfortunately installing it through pip install opencv-contrib-python doesn't include everything I need. So, I've built it from source, and the library itself seem to be working fine. The build process installed some things into ./Anaconda3/envs/cv/Lib/site-packages/cv2/: __init__.py, some config py files, and .../cv2/python-3.8/cv2.cp38-win_amd64.pyd. I'm not sure if it did anything else.

但是我在这里:

  • 在单独的环境中,pip install opencv-contrib-python既运行又具有自动完成功能
  • 在这种环境下,OpenCV实际上运行良好,但是自动完成功能不起作用,Pycharm抱怨所有内容,例如:Cannot find reference 'imread' in '__init__.py'
  • 使缓存无效/重新启动无济于事
  • 删除并重新添加环境无济于事
  • 删除Pycharm的用户首选项文件夹无济于事
  • 重建/安装OpenCV没有帮助
  • 文件->设置->项目->项目解释器设置正确
  • 运行->编辑配置-> Python解释器设置正确
  • In a separate environment, a pip install opencv-contrib-python both runs and has autocomplete working
  • In this environment, OpenCV actually runs just fine, but the autocomplete doesn't work and Pycharm complains about everything, eg: Cannot find reference 'imread' in '__init__.py'
  • Invalidate Caches / Restart doesn't help
  • Removing and re-adding the environment doesn't help
  • Deleting the user preferences folder for Pycharm doesn't help
  • Rebuilding/Installing OpenCV doesn't help
  • File->Settings->Project->Project Interpreter is set correctly
  • Run->Edit Configuration->Python Interpreter is set correctly

所以我的问题是:Pycharm如何获取或生成该自动完成信息?看起来pyd文件只是一个变相的dll,并且在其他环境的site-packages/cv2文件夹中浏览时,我看不到任何有趣的东西.我已经读过__init__.py与它有关,但是pip版本再次不包含任何东西(除了有from .cv2 import *,但是我不确定这是怎么造成的).您可以下载的.whl文件是一个zip文件,仅包含与"pip install"得到的文件相同的文件.

So my question is: how does Pycharm get or generate that autocomplete information? It looks like the pyd file is just a dll in disguise, and looking through the other environment's site-packages/cv2 folder, I don't see anything interesting. I've read that __init__.py has something to do with it, but again the pip version doesn't contain anything (except there's a from .cv2 import *, but I'm not sure how that factors in). The .whl file you can download is a zip that only contains the same as what 'pip install' gets.

自动完成信息存储在哪里?也许有某种方法可以将其从一个环境复制到另一个环境?这几乎将我带到了那里,在这一点上,我认为这已经足够了.也许我需要用我错过的另一个标志来重建它?

Where does the autocomplete information get stored? Maybe there's some way to copy it from one environment to another? It would get me almost all the way there, which at this point would be good enough I think. Maybe I need to rebuild it with another flag I missed?

推荐答案

或者将包含.pyd文件的目录添加到解释器路径.

Alternatively add the directory containing the .pyd file to the interpreter paths.

使用从源代码编译并安装在Conda环境和PyCharm 2020.1中的OpenCV 4.2.0,我确实遇到了这个问题.

I had exactly this problem with OpenCV 4.2.0 compiled from sources, installed in my Conda environment and PyCharm 2020.1.

我这样解决了:

  1. 选择项目解释器
  2. 单击旁边的设置按钮,然后单击显示所选解释器的路径"
  3. 添加包含cv2库的目录(在本例中为Conda Python库路径-例如miniconda3/lib/python3.7/site-packages/cv2/python-3.7).通常,请检查site-packages/cv2/python-X.X目录)

这篇关于从源代码构建的OpenCV:Pycharm无法获取自动完成信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆