简体   繁体   English

Pycharm,PyQt5和Python 2.7 - 无代码完成

[英]Pycharm, PyQt5, and Python 2.7 — No code completion

I've got: 我有:

  • Python 2.7 ( Anaconda x64 ), which works great Python 2.7( Anaconda x64 ),效果很好
  • PyQt5 (installed using pip install python-qt5 ) PyQt5 (使用pip install python-qt5
  • PyCharm 4.04 Professional (recently upgraded from 3.4.1) PyCharm 4.04 Professional(最近从3.4.1升级)
  • A small Qt application 一个小的Qt应用程序

After much hair-pulling (since Riverbank doesn't provide a PyQt5 binary for Python 2.7, only for 3.3+) I got everything working thanks to Marcus Otosson's pre-compiled binary packages. 经过多次拉动(因为Riverbank没有为Python 2.7提供PyQt5二进制文件,只有3.3 +),感谢Marcus Otosson的预编译二进制包,我得到了一切。

Qt is now installed and fully functional. Qt现已安装并且功能齐全。 My Qt application runs great! 我的Qt应用程序运行得很好!

But the application isn't finished yet, and PyCharm won't do code completion for the PyQt modules. 但是应用程序还没有完成, PyCharm也不会为PyQt模块完成代码 It won't even recognize that any PyQt5 sub-modules (like Qwidgets) exist: even though they work just fine, I still get the red squiggly "Unresolved Reference" warning. 它甚至不会识别任何PyQt5子模块(如Qwidgets)存在:即使它们工作得很好,我仍然会得到红色波浪形的"Unresolved Reference"警告。

How do I fix this? 我该如何解决? I assume this has to do with the inherent difficulties in generating skeletons for binary *.pyd files. 我认为这与生成二进制*.pyd文件的骨架的固有困难有关。 How does it work exactly? 它是如何工作的? Can I manually generate code skeletons, or import them from somewhere they generated correctly? 我可以手动生成代码框架,还是从它们正确生成的某个位置导入它们?

Uninstalling and re-installing PyCharm didn't help. 卸载并重新安装PyCharm没有帮助。 Neither did re-configuring the interpreter to force the skeleton generator to run again. 也没有重新配置解释器以强制骨架生成器再次运行。

Please help before I go bald. 在我去秃头之前请帮忙。

I am using PyCharm4(community Edititon) on Windows with PyQt4, the autocomplete is fine. 我在使用PyQt4的Windows上使用PyCharm4(社区Edititon),自动完成很好。 As PyQt4 is actually a dynamic library to be dynamic loaded by the python interpreter ( you can look into the PyQt4 folder, there is no python files there except some init .py), auto-complete depends on the source code of PyQt4 itself, so when using pycharm, it usually generally some local python cache for complete. 由于PyQt4实际上是一个由python解释器动态加载的动态库(你可以查看PyQt4文件夹,除了一些init .py之外没有python文件),auto-complete依赖于PyQt4本身的源代码,所以当使用pycharm时,它通常通常会有一些本地python缓存来完成。 For my machine, a typically file looks like: C:\\Users\\cui.PyCharm40\\system\\python_stubs-762174762\\PyQt4\\QtCore\\QString.py 对于我的机器,通常的文件如下所示:C:\\ Users \\ cui.PyCharm40 \\ system \\ python_stubs-762174762 \\ PyQt4 \\ QtCore \\ QString.py

You can also try install PyQt document from Pycharm. 您也可以尝试从Pycharm安装PyQt文档。 File->settings->Tools->python external document->PyQt 文件 - >设置 - >工具 - > python外部文档 - > PyQt

Can you find PyQt5 from your project's External Libraries? 你能从项目的外部库中找到PyQt5吗? If you install it through pip, you should be able to see the library directly. 如果您通过pip安装它,您应该能够直接看到该库。 Once the library can be referred, it will do the code-completion for you. 一旦可以引用库,它将为您完成代码完成。

Had the same problem in PyCharm 2017.1.1. 在PyCharm 2017.1.1中遇到同样的问题。 Don't do 不要这样做

import PyQt5.QtWidgets

do

from PyQt5 import QtWidgets

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

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