简体   繁体   English

仅在 PyCharm 的编辑器中缺少 qgis.core 模块中的类

[英]Missing classes from qgis.core module only in PyCharm's editor

I would like to use PyCharm Community Edition 2020.1.2 x64 on Windows 10 as IDE for writing QGIS plugins.我想在 Windows 10 上使用 PyCharm Community Edition 2020.1.2 x64 作为 IDE 来编写 QGIS 插件。 I need to base on old version - QGIS 2.18, so I need python 2.7, qt4, and also core modules from QGIS 2.18.我需要基于旧版本 - QGIS 2.18,所以我需要 python 2.7、qt4 以及来自 QGIS 2.18 的核心模块。 I downloaded QGIS 2.18 from official site.我从官方网站下载了 QGIS 2.18。 It provides a ready to use python environment as.bat script, that sets all needed python paths.它提供了一个随时可用的 python 环境 as.bat 脚本,设置所有需要的 python 路径。 So I used path D:\Program Files\QGIS 2.18\bin\python-qgis-ltr.bat to set main python interpreter for my project.所以我使用路径D:\Program Files\QGIS 2.18\bin\python-qgis-ltr.bat为我的项目设置主 python 解释器。

After that I was able to run python console in PyCharm, import all QGIS modules, and any classes from QGIS standard collection like QgsFeature, QgsVectorLayer etc. Everything was fine untill I tried to import this classes from PyCharm editor in.py file as from qgis.core import QgsFeature . After that I was able to run python console in PyCharm, import all QGIS modules, and any classes from QGIS standard collection like QgsFeature, QgsVectorLayer etc. Everything was fine untill I tried to import this classes from PyCharm editor in.py file as from qgis.core import QgsFeature In editor PyCharm sees the package qgis.core and I'm able to import it, but PyCharm's code completion inside the module sees only classes that are saved in D:\Program Files\QGIS 2.18\apps\qgis-ltr\python\qgis\core\__init__.py eg QgsEditError class, but all standard QGIS class underlines on red.在编辑器 PyCharm 看到 package qgis.core并且我能够导入它,但是 PyCharm 在模块内的代码完成只看到保存在D:\Program Files\QGIS 2.18\apps\qgis-ltr\python\qgis\core\__init__.py例如 QgsEditError class,但所有标准 QGIS class 下划线为红色。

Python console ran on exactly the same interpreter see the same sources as are visible in "External Libraries" tab in PyCharm, so command: Python 控制台运行在完全相同的解释器上查看与 PyCharm 的“外部库”选项卡中可见的相同源,因此命令:

  • qgis.core.__path__ returns ['D:\\Program Files\\QGIS 2.18\\apps\\qgis-ltr\\python\\qgis\\core'] , qgis.core.__path__返回['D:\\Program Files\\QGIS 2.18\\apps\\qgis-ltr\\python\\qgis\\core']
  • qgis.core.__file__ returns 'D:\\Program Files\\QGIS 2.18\\apps\\qgis-ltr\\python\\qgis\\core\\__init__.pyc , qgis.core.__file__返回'D:\\Program Files\\QGIS 2.18\\apps\\qgis-ltr\\python\\qgis\\core\\__init__.pyc
  • dir(qgis.core) returns full list of QGIS standard core classes. dir(qgis.core)返回 QGIS 标准核心类的完整列表。

If I run the.py script, in which PyCharm's code validator is showing incorrect import object by red underline, the script is executed without any error and I can easly print the imported QgsFeature object.如果我运行 .py 脚本,其中 PyCharm 的代码验证器通过红色下划线显示不正确的导入 object,脚本执行没有任何错误,我可以轻松打印导入的 QgsFeature object。 Why my PyCharm's editor see different content of qgis.core module then console ran also from IDE on exactly the same interpreter?为什么我的 PyCharm 的编辑器看到 qgis.core 模块的不同内容然后控制台也在完全相同的解释器上从 IDE 运行?

Allow me to qualify myself.请允许我证明自己。 I lost interest for adventures and trail blazing in computing some time ago.不久前,我对冒险和开拓计算失去了兴趣。 I won some big battles and lost some too.我赢了一些大战役,也输了一些。 And I unnecessary wasted a lot of time that could have been better spent.而且我不必要地浪费了很多本来可以更好地度过的时间。 Nowadays, I just wait a reasonable period of time before upgrading anything, and wait a spell before downloading the newest anything, and pretty much avoid trying to do things outside a conventional path.如今,我只是在升级任何东西之前等待一段合理的时间,并在下载最新的任何东西之前等待一段时间,并且几乎避免尝试在常规路径之外做事。

So your post got me curious and I looked around some.所以你的帖子让我很好奇,我环顾四周。 I found very little information about PyCharm being used building QGIS plugins.我发现关于 PyCharm 用于构建 QGIS 插件的信息很少。 That pretty much tells me all I want to know: that it's not real common for PyCharm to be used in building QGIS plugins.这几乎告诉了我我想知道的一切:PyCharm 用于构建 QGIS 插件并不常见。

But there was quite abit of information about building QGIS plugins with python.但是有很多关于使用 python 构建 QGIS 插件的信息。 There's even a QGIS Tutorial & Tips on the subject.甚至还有关于该主题的 QGIS 教程和提示。 QGIS suggests using the Qt Creator and further goes on to say that QGIS itself is written using the QT framework. QGIS 建议使用 Qt Creator 并进一步说 QGIS 本身是使用 QT 框架编写的。 "For plugin development, we use an application called Qt Creator." “对于插件开发,我们使用名为 Qt Creator 的应用程序。”

If you overcome your current predicament I'd like to hear how you accomplished it.如果你克服了目前的困境,我想听听你是如何做到的。

For what it's worth, here's the link to the QGIS Tutorials & Tips.对于它的价值,这里是 QGIS 教程和提示的链接。

https://www.qgistutorials.com/en/docs/building_a_python_plugin.html https://www.qgistutorials.com/en/docs/building_a_python_plugin.html

Finally, the problem solved itself.最后,问题自己解决了。 It was something wrong with building a binary skeletons of C++ libraries, what PyCharm does every time the application is launched.构建 C++ 库的二进制骨架是有问题的,每次启动应用程序时 PyCharm 所做的事情。 My PyCharm didn't want to do it and I found many similar problems with other libraries (eg Qt) that people were struggling with.我的 PyCharm 不想这样做,我发现人们正在努力解决的其他库(例如 Qt)有许多类似的问题。 After two days my PyCharm just fixed itself and created all needed binary skeletons for my QGIS libraries.两天后,我的 PyCharm 刚刚自行修复并为我的 QGIS 库创建了所有需要的二进制骨架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM