7

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.

Matt Merrifield
  • 417
  • 6
  • 14
  • You could also contact JetBrains directly: https://intellij-support.jetbrains.com/home – NoDataDumpNoContribution Jan 29 '15 at 09:24
  • Good idea -- I just posted a support request. StackOverflow tends to be speedier, and is often just as helpful as official channels. – Matt Merrifield Jan 29 '15 at 22:00
  • This does work for me on WIndows x64. I too am running professional. "Qt is now installed and fully functional." So you've tested it from the command line? – IronManMark20 May 26 '15 at 22:14
  • I have installed pyqt5 for python2.7 through Anaconda (conda install pyqt==5.6.0). I had the same issue, but a simple restart of pycharm solved it. If that doesn't work "File -> Invalidate Caches / Restart" might. – hardsetting Jun 17 '17 at 12:23

3 Answers3

1

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.

Ellis Shen
  • 227
  • 1
  • 3
  • 12
  • Yes, I can. PyQt4 and PyQt5 are both installed in `C:\Anaconda\Lib\site-packages\`, and viewable from PyCharm. That's the funny thing: I had assumed it would "just work", but it doesn't. There are a bunch of Qt-labeled *.dll and *.pyd available in those folders too. But PyCharm's autocomplete doesn't recognize them. – Matt Merrifield Jan 29 '15 at 05:55
  • Side note: PyQt4/5 will not install with pip. They don't use a setup.py file, and aren't hosted on Pypi.org. You have to install binary packages (which include the Qt5 DLL files) from riverbankcomputing – Matt Merrifield Feb 06 '15 at 01:02
1

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

Cui Heng
  • 1,265
  • 8
  • 10
  • Progress! I have a PyQt5 folder in python_stubs, but there's only two files in it: __init__.py and Qt.py. "from PyQt5 import Qt" doesn't throw an unresolved reference warning, so If I populated this folder with all the PyQt5 stubs, maybe autocomplete would work? Do you have a working installation of PyQt5 skeletons you could throw up on pastebin? – Matt Merrifield Jan 29 '15 at 18:28
  • I am not sure if there are some other setting different from your PC and mine, for my PC, if I deleted the completion foldr "/Users/mac/Library/Caches/PyCharm40/python_stubs/348993582/PyQt4", then restart the PyCharm, open a new folder, create a python file, then If I just type "from PyQt4.QtCore import QString", then Pycham will try to create index for all libraries ( this may take a while), after this is done, all .py files for PyQt4 will automated download to the python_stubs folder. – Cui Heng Jan 30 '15 at 00:09
  • 1
    Almost worked. My PyQt5 skeleton folder is in "D:\Users\mmerrifield\.PyCharm40\system\python_stubs\-946255732\PyQt5". When I delete it, and re-start pycharm, it builds an incomplete skeleton. The only files available are "__init__.py" and "Qt". For what it's worth (very little in my case) the PyQt4 skeletons generated fine. – Matt Merrifield Feb 06 '15 at 01:04
  • So PyQt4 works now, but PyQt5 does not. Any idea why? – Matt Merrifield Feb 06 '15 at 18:29
  • I have not used PyQt5 yet, so I could not tell why it doesn't work for PyQt5. but as noticed in the pycharm setting, there is file -》 setting-》python external document, there is only pyQt4 document exist, so how about trying to add a similar PyQt5 document url and restart pycharm, see it work? – Cui Heng Feb 08 '15 at 10:18
  • There is no documentation to speak of, really. Only a [list of classes](http://pyqt.sourceforge.net/Docs/PyQt5/class_reference.html), each of which only links to the C++ documentation. Don't get me wrong: it's helpful information since the python methods map 1:1 to the C++ methods, but it's not close enough or in a standard format PyCharm would be able to parse. – Matt Merrifield Feb 09 '15 at 17:25
1

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

import PyQt5.QtWidgets

do

from PyQt5 import QtWidgets
Lars
  • 23
  • 3