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

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

问题描述

在编写Python code。使用编译的扩展(OpenCV的Python绑定为例),PyCharm似乎并没有意识到自己的可用性。进口标有下划线的灰色,称尚未解决的引用作为提示,和自动完成不工作,要么。 (除了在code已经使用功能名称。)

这是不是错误的模块路径造成的,code没有错误启动时运行。另外,我在导入一个Python外壳模块后,自动完成开始按预期工作。

有没有一个解决方案或这是编译的扩展的体系结构限制?有没有设法解决这个问题的任何其他IDE?


解决方案

  

进口标有下划线的灰色,称尚未解决的引用作为提示


这很可能意味着,PyCharm不能见你导入模块。在编辑模式下,PyCharm依赖于进口模块的Python源的可用性。如果模块不是用Python写,但是是一个C扩展模块,PyCharm生成一个'骨架'包含函数原型,并用它完成。

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

请确保您的OpenCV的安装是再明显不过了Python间preTER您选择的项目(File /设置/ Python的跨preTER)。如果跨preTER是正确的,请尝试删除并重新添加它(这是费时一点,抱歉)。

如果没有什么帮助,提交错误

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.)

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.

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

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.

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

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).

If nothing helps, file a bug.

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

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