Pycharm, PyQt5, and Python 2.7 — No code completio

2019-03-13 15:04发布

I've got:

  • Python 2.7 (Anaconda x64), which works great
  • PyQt5 (installed using pip install python-qt5)
  • PyCharm 4.04 Professional (recently upgraded from 3.4.1)
  • A small Qt application

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.

Qt is now installed and fully functional. My Qt application runs great!

But the application isn't finished yet, and PyCharm won't do code completion for the PyQt modules. 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.

How do I fix this? I assume this has to do with the inherent difficulties in generating skeletons for binary *.pyd files. 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. Neither did re-configuring the interpreter to force the skeleton generator to run again.

Please help before I go bald.

3条回答
冷血范
2楼-- · 2019-03-13 15:14

I am using PyCharm4(community Edititon) on Windows with PyQt4, the autocomplete is fine. 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. For my machine, a typically file looks like: C:\Users\cui.PyCharm40\system\python_stubs-762174762\PyQt4\QtCore\QString.py

You can also try install PyQt document from Pycharm. File->settings->Tools->python external document->PyQt

查看更多
Animai°情兽
3楼-- · 2019-03-13 15:22

Can you find PyQt5 from your project's External Libraries? If you install it through pip, you should be able to see the library directly. Once the library can be referred, it will do the code-completion for you.

查看更多
来,给爷笑一个
4楼-- · 2019-03-13 15:27

Had the same problem in PyCharm 2017.1.1. Don't do

import PyQt5.QtWidgets

do

from PyQt5 import QtWidgets
查看更多
登录 后发表回答