Windows 中 OpenCV-Python 的自动完成功能不起作用 [英] Autocomplete for OpenCV-Python in Windows not working

查看:35
本文介绍了Windows 中 OpenCV-Python 的自动完成功能不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在 Windows 上为 OpenCV (Python) 自动完成工作.

I cannot get autocomplete working for OpenCV (Python) on Windows.

根据 Abid 的说明此处,我将 cv2.pyd 文件粘贴到 C:Python27Libsite- 包.

According to Abid's instructions here, I pasted the cv2.pyd file in the C:Python27Libsite-packages.

在Python代码中,我是这样导入的:

In the Python code, I import as follows:

import cv2.cv as cv

我还安装了 numpy,它在站点包中创建了自己的文件夹,这与 OpenCV(我直接粘贴到站点包中)不同.

I have also installed numpy, and it created its own folder in site-packages unlike OpenCV (which I've pasted directly into site-packages).

通过这种设置,即使调用 OpenCV 方法,代码也可以毫无问题地执行.

With this setup, the code executes without any problems, even when OpenCV methods are called.

但我一直无法让自动完成工作.我试图让它在 Sublime Text 2(使用 SublimeCodeIntel)和 PyCharm 上工作.在这两种 IDE 中,自动完成功能适用于 numpy 导入,但无法用于 OpenCV 导入.

But I have not been able to get autocomplete to work. I have tried to get it to work on Sublime Text 2 (with SublimeCodeIntel) and PyCharm. In both IDEs, autocomplete works for the numpy import, but fails for the OpenCV import.

我使用的是 OpenCV 2.4.6 和 Python 2.7(32 位).

I'm using OpenCV 2.4.6, and Python 2.7 (32 bit).

任何可能的解决方案?

推荐答案

它不工作的原因是因为您使用的是 .pyd 文件,即 本质上与编译的 .dll 相同.自动完成通过读取纯文本源 .py 文件来工作.尝试安装 OpenCV 和 Intel Math内核库优化了来自 Christoph 的 NumPy 包Gohlke 的 Windows 的 Python 扩展包 存储库,该存储库经常更新,并且必须-为在 Windows 上进行任何类型的 Python 科学计算的任何人使用资源.确保首先从 site-packages 中删除 cv2.pydnumpy 目录.这些新包将安装 Sublime Text 中自动完成引擎所需的 .py 源文件.

The reason it's not working is because you're using a .pyd file, which is essentially the same as a compiled .dll. Autocomplete works by reading the source .py files, which are plain text. Try installing the OpenCV and Intel Math Kernel Library optimized NumPy packages from Christoph Gohlke's Python Extension Packages for Windows repository, which is frequently updated and a must-use resource for anyone who does any kind of scientific Python computing on Windows. Make sure you delete the cv2.pyd and numpy directories from site-packages first. These new packages will install the .py source files needed by the autocomplete engine in Sublime Text.

编辑

好的,所以我写了上面的内容,因为它适用于许多其他软件包.我是一个 Python 3 人,我从来没有安装 Gohlke 的 OpenCV,因为它只有 Python 2 绑定.阅读@CrazyCoder 的评论后 下面,我启动了 Win7,确实他是完全正确的(我之前应该意识到这一点)——因为 OpenCV 是用 C/C++ 编写的,所以 Gohlke 包中包含的唯一 .py 文件是cv.py,其全部内容如下:

OK, so I wrote the above because it worked well for a bunch of other packages. I'm a Python 3 guy, and I never installed OpenCV from Gohlke because it only has Python 2 bindings. After reading @CrazyCoder's comment below, I booted up Win7, and indeed he's absolutely correct (and I should have realized this before) - since OpenCV is written in C/C++, the only .py file included in the Gohlke package is cv.py, whose entire contents are as follows:

from cv2.cv import *

其余的包含在cv2.pyd和一堆.dll中.来自 opencv.org 的完整 OpenCV Windows 发行版是 291 MB 的下载,扩展到 3 GB,以及少数 .py 文件涉及构建 OpenCV,对于自动完成目的没有任何好处.所以,不幸的是,我不知道目前是否有解决您的问题的方法.把 docs 放在手边,也许可以看看 OpenCV Computer Vision with Python 来自 Packt/O'Reilly,于 2013 年 4 月发布.

The rest is contained in cv2.pyd and a bunch of .dlls. The full OpenCV Windows distribution from opencv.org is a 291 MB download, which expands to 3 GB, and the few .py files in there are involved in building OpenCV, and aren't any good for autocomplete purposes. So, unfortunately, I don't know if there's a solution to your problem at the moment. Just keep the docs handy, and perhaps check out OpenCV Computer Vision with Python from Packt/O'Reilly, published in April 2013.

这篇关于Windows 中 OpenCV-Python 的自动完成功能不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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