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.
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.
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
Had the same problem in PyCharm 2017.1.1. Don't do
import PyQt5.QtWidgets
do
from PyQt5 import QtWidgets
Related
I am using PyQt5 in PyCharm Community Edition. I have installed qt5-serialport as described in this question and when I use python on the command line I am able to do from PyQt5.QtSerialPort import QSerialPort and use the QSerialPort module with no problem in the interactive python environment and when running a python script that makes use of the QSerialPort module, so it's clear that python itself is finding the module just fine. However in PyCharm, the module is not found despite the fact that I'm using the system python as the interpreter. On the line from PyQt5.QtSerialPort import QSerialPort PyCharm underlines QSerialPort in red and it doesn't offer any tooltip suggestions for methods etc. on any QSerialPort object I instantiate.
Normally when I get this kind of problem I install the package using the installer within PyCharm but this particular package doesn't seem to be in any public repo listing I can find. (Somehow yay found it, despite it not being listed in the searchable AUR). Other modules in the PyQt5 package import in PyCharm without problems. How can I get PyCharm Community Edition to recognize this module?
Installing it on the terminal should work using pip from python.org.
pip install PyQt5
This approach appears to work since it has the core features for finding, downloading, and installing packages from various Python package indexes. More info on pip from python.org.
According to the Troubleshooting tips from JetBrains listed for PyCharm, there is useful info on debugging import errors using PyQt. So this may be the cause as to why installation through the IDE was not working even though PyQt was installed on the interpreter.
OK, so I need to make a project in PyQt, and I'm using PyQt4 since I found more tutorials on this and it is easier for me.
I installed PyCharm as my IDE. I haven't had any python compilers so I installed Python 3.7.5 (from Microsoft Store since PyCharm recommended that), and configured the interpreter in PyCharm (so now, python works)
Then, I needed to install PyQt4, and since it didn't work from PyCharm's project interpreter -> install package, I downloaded "PyQt4-4.11.4-cp37-cp37m-win_amd64" and installed it with pip.
Then, I installed sip also with pip.
The thing is that I get an error in my code in PyCharm.
from PyQt4 import QtGui
ModuleNotFoundError: No module named 'sip'
I also configured all my Windows PATHs, when I installed sip it gave me an error saying that the path isn't added. I added that path.
I also added the pyqt4 path.
These are my paths:
C:\Users\b997a\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\sipbuild
C:\Users\b997a\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages
'C:\Users\b997a\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\Scripts
And these are all the packages I think I have installed in PyCharm:
Do you know what I can do? I really don't want to use PyQt5 since I know a found tutorials on exactly what I want to do on PyQt4 and I don't really have time to learn PyQt5 now...
I also tried to see if Python 3.7.5 Shell (IDLE) will raise an error, and yes, it did. I have the same error in Python's IDLE.
What is the problem? It worked for a while until I deleted Python a few weeks ago, but now it doesn't work anymore.
Thanks a lot!
I have recently faced such issues, so my recommendations are:
It's good to activate your virtual env for your project.
Usually pip should install the required binaries, but if it doesn't, try searching the same from pycharm -> settings and add directly from there. This has always worked for me.
P.S. I was not able to add comment, so I posted it as answer.
I've packaged a python application written in Python 3.6 with PyQt5 using PyInstaller for MacOS. The application runs correctly, but the interface does not use a native-looking style. Running the program manually does use the correct style, and PyQt.QtWidgets.StyleFactory.keys() gives 'macintosh', 'Windows', and 'Fusion'. When running the packaged application, only 'Windows' and 'Fusion' are available. How can I package the 'macintosh' style with my application and instruct PyQt5 to use the native style?
The error seems to have been fixed in a unmerged branch of PyInstaller. More information can be found on the GitHub pull request conversation, but reinstalling PyInstaller using pip install https://github.com/bjones1/pyinstaller/archive/pyqt5_fix.zip fixed the style issue for me.
An extremely minor problem, but an annoying one all the same- as you can see in the picture below, some references are resolved correctly by the linter (like pyqtSignal and pyqtSlot), and some are not (pyqtProperty).
What's even weirder is that code using these 'unresolved' references run just fine, it's just the linter/syntax highlighter that can't seem to find this reference.
Software used:
PyCharm 2017.3 (but this also happened on PyCharm 2017.2.X as well)
Python 3.6.3
PyQt 5.6.0, Qt 5.6.2
Windows 10 Pro x64
I'm unable to install these packages on my machine in order to check, but this likely isn't an issue with PyCharm.
Try Ctrl+Click on QtCore. I'm guessing this will take you to a file. Is pyqtProperty in that file? I'm guessing not. However, I'm guessing pyqtSignal and pyqtSlot are.
A couple reasons come to mind for why this might be happening
pyqtProperty is not supported with version 5.6.0 and you need to install a different version
The the Python interpreter which you are using does not actually have the version installed which you think
Is PyQt a python wrapper around a c++ package? I've seen it before where essentially the package was made wrong and the calls still went to c++ correctly, but they did not add in the Python object declarations correctly such that IDEs recognized them and a bug needed to be placed on the package's github.
I made a GUI Python program using the PyQt4 framework on a Linux computer, and now I am on a MacBook Pro and I would like to be able to package my program. The program imports PyQt4 (obviously), along with other libraries like Pandas. I just tried downloading PyQt4 on my OS but do not know exactly what is going on. I just want to be able to include the necessary PyQt4 files in the package so that any user can run my program without having to download PyQt4. Is that possible?
Also, I'm using py2app to try to package this desktop app. Others have suggested using MacPorts along with py2app, and I tried downloading MacPorts but was also unable to figure that out.
Any help would be greatly appreciated!