在 PyCharm 中为 Python 编译的扩展自动完成 [英] Autocomplete in PyCharm for Python compiled extensions

查看:27
本文介绍了在 PyCharm 中为 Python 编译的扩展自动完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用编译扩展(例如 OpenCV Python 绑定)编写 Python 代码时,PyCharm 似乎不知道它们的可用性.导入用灰色下划线标记,表示未解析的引用"作为工具提示,并且自动完成也不起作用.(代码中已经使用的函数名除外.)

When writing Python code using compiled extensions (the OpenCV Python bindings, for example), PyCharm doesn't seem to be aware of their availability. The imports are marked with a grey underline, saying "unresolved reference" as a tooltip, and autocomplete doesn't work, either. (Except for the function names already used in the code.)

这不是由错误的模块路径引起的,代码在启动时运行没有错误.此外,在我在 Python shell 中导入模块后,自动完成开始按预期工作.

This isn't caused by wrong module paths, the code runs without error when started. Also, after I import the modules in a Python shell, autocomplete starts working as expected.

是否有解决方案,或者这是编译扩展的架构限制?有没有其他 IDE 可以解决这个问题?

Is there a solution for that or is this an architectural limitation for compiled extensions? Are there any other IDEs that manage to cope with this problem?

推荐答案

导入用灰色下划线标记,表示未解析的引用"作为工具提示

The imports are marked with a grey underline, saying "unresolved reference" as a tooltip

这很可能意味着 PyCharm 无法看到您导入的模块.在编辑模式下,PyCharm 依赖于导入模块的 Python 源的可用性.如果一个模块不是用 Python 编写的而是一个 C 扩展模块,PyCharm 会生成一个包含函数原型的骨架",并使用它来完成.

This most probably means that PyCharm can't see the module you import. In editing mode, PyCharm relies on availability of Python sources of imported modules. If a module is not written in Python but is a C extension module, PyCharm generates a 'skeleton' that contains function prototypes, and uses it for completion.

在 shell 模式下,PyCharm 使用实时导入的对象来完成,结果略有不同.

In shell mode, PyCharm uses live imported objects for completion, with slightly different results.

确保您的 OpenCV 安装对于您为项目选择的 Python 解释器(文件/设置/Python 解释器)可见.如果解释器正确,请尝试删除并重新添加它(这有点费时,抱歉).

Make sure that your OpenCV installation is visible for the Python interpreter you chose for the project (File / Settings / Python interpreter). If the interpreter is correct, try removing and re-adding it (this is time-consuming a bit, sorry).

如果没有任何帮助,提交错误.

这篇关于在 PyCharm 中为 Python 编译的扩展自动完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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