advice about the PyQt5 - python

Im working on application design using Qt Design. the design completed so now i want to connect it with Python 3.6.4 using pycharm. and import PyQt5. i already installed PyQt5 as you can see.
PS C:\Users\Tariq> pip install pyqt5
Requirement already satisfied :pyqt5 in
c:\users\tariq\appdata\local\programs\python\python36-32\lib\site-packages
Requirement already satisfied: sip<4.20,>=4.19.4 in
c:\users\tariq\appdata\local\programs\python\python36-32\lib\site-packages
(from pyqt5)
also i installed PyQt5 inside pycharm as you can see in the picture.
Press enter to show the image that PyQt5 installed inside pycharm
My Problem that the PyQt5 unknown for pycharm and this error appear
from PyQt5.QtWidgets import*
ModuleNotFoundError: No module named 'PyQt5
'

The way that has always worked for me is below.
from PyQt5 import QtCore, QtGui, QtWidgets

This maybe due to the way you set up your environment variable add this c:\Python3*\Script,C:\Python3*\Lib\site-packages\, and C:\Python34\Lib\site-packages\PyQt5\ in your environmental path, hope it works. '*` is the version of python e.g Python34

Related

VS Code can retrive PyQt5.uic

I am trying to learn PyQt5 but found issue below;
I installed PyQt5 successfully and all modules are working but not PyQt5.uic
Please see below image. I tried to uninstall PyQt5 and reinstall it but stil not working.
Thanks in advance
image

PyQt6 Successfully Installs but cannot be imported

I donwloaded PyQt6 using pip install pyqt6 and it had a bunch of errors so I uninstalled it and reinstalled it with pip install pyqt6 --user and the errors dissappeared. problem is trying to use it in VSCODe or any other ide doesn't work. When i write:
from PyQt6.QtWidgets import QApplication, QMainWindow, QAction, QMenu, QMessageBox VSCode gives me the error Import "PyQt6.QtWidgets" could not be resolved. Could someone walk me through what I may of done wrong please?
Try this in VSCode:
On the lower right of the VSCode window you should see the language
mode and version that VSCode is currently using. Something like "Python" 3.10.7.
If you HOVER over this text (like 3.10.7), VSCODE will display the
actual path used for that version.
If you CLICK on the version, you can change the LANGUAGE MODE and VERSION that is being used by VSCode in the window while editing (and executing) Python code. The language and version reflect the path to the library used.
In my case when I looked, the version had changed to a beta version I'd mistakingly installed earlier (3.11.03b). The version I was using when I installed PyQT6 was 3.10.7.
When I changed the version back to 3.10.7, suddenly everything worked again.
In my case, I had been moving things around in migrating from PyQT5 to PyQT6 and was now using a different file folder for my migrated code. I opened up a new VSCode Window and then my new PyQT6 folder, and I failed to notice that VSCode had chosen what it thought was the 'latest' version of the interpreter.

PyCharm Error, ModuleNotFoundError: No module named 'PyQt5'

I installed python 3.7 and PyQt5 using pip install PyQt5 command. when I import the module in python console of pycharm, it is working alright but when I import it into my project files am getting the following error. I searched through the internet for possible solutions but are not working for me and I also think my problem is different from those that were already asked. any help?
from PyQt5 import QtCore, uic, QtWidgets
from PyQt5.uic import loadUi
from PyQt5.QtWidgets import QApplication,QDialog
import sys
UIClass, QtBaseClass = uic.loadUiType("projj/firstly.ui")
class MyApp(UIClass, QtBaseClass):
def __init__(self):
UIClass.__init__(self)
QtBaseClass.__init__(self)
self.setupUi(self)
self.setWindowTitle('developer in details')
self.pushButton.clicked.connect(self.on_pushButton_clicked)
self.pushButton_2.clicked.connect(self.on_pushButton_clicked_2)
self.pushButton_6.clicked.connect(self.on_pushButton_clicked_6)
and the error am getting is
Traceback (most recent call last):
File "C:/Users/pc/PycharmProjects/presents/Main.py", line 1, in <module>
from PyQt5 import QtCore, uic, QtWidgets
ModuleNotFoundError: No module named 'PyQt5'
I find out that I can just use the available tool in PyCharm which is the IDE am using for python. By just clicking the red underlined word PyQt5 in this case and a red bulb will appear to the left end of the line >> click the drop down that appear and select install package PyQt5. it installs the required staff again and everything works fine then.
It sounds like the Python Console and your project are running two different Python Interpreters.
When you start the Python Console the top line should list the interpreter it's using. This is the one you installed PyQt5 to.
Go to: File -> Settings -> Project: xxxxx -> Project Interpreter and change it to the one that's in your Python Console. (Note you may need to add another interpreter by clicking on the gear to the right of the text box listing the interpreters)
Installing PyQt5 like this worked for me:
python -m pip install PyQt5
You can try to reinstall PyQt5 like this:
pip uninstall PyQt5
python -m pip install PyQt5

Python - PyQt5 [PyQt5.QtWidgets import QApplication 'No Module']

I have been attempting to learn PyQt5 in order to create GUI.
Pip installed the PyQt5 & the PyQt5.tools yet when I attempt to use it
using Visual Studio Code (while having the Python Extension of VS Code installed) I receive an error.
VS Code detects PyQt5 up to PyQt5.QtWidgets, yet it says no module inside QtWidgets named QApplication can be found.
Import Error of VS Code
On the contrary when it comes to the error, when I attempt to import QApplication from python.exe, no errors nor problems are presented.
Python.exe 'from PyQt5.QtWidgets import QApplication'
This leads me into thinking the problem resides at VS Code's doorstep..
Thanks for your time/answers.
open the cmd from start menu (Command Prompt)
type pip install pyqt5
type pip install pyqt5-stubs
install the integration of PyQt5 from VSCode Marketplace
if is it still not working try uninstalling PyQt5 (pip uninstall pyqt5)
and install it again
Search "PYQT Integration" on ur VS Code Extension shop
Install it
Set the configurations (ur pyqtdesigner path and pyuic etc)
this may help u
I had the same problem with lots of modules specially pytube . PyQt6 , It was all resolved when I changed my interpreter to python 3.11

Setting up IPython Qtconsole with PyQt5

On an OSX 10.9, I have Qt5 installed. Later I installed Ipython, sip and PyQt5 all build from source. Now here is the problem: when I try to run ipython qtconsole, I have a bunch of errors related to the files in this directory (and its subfolders)
/Library/Python/2.7/site-packages/IPython/
followed by
ImportError:
Could not load requested Qt binding. Please ensure that
PyQt4 >= 4.7 or PySide >= 1.0.3 is available,
and only one is imported per session.
Currently-imported Qt library: None
PyQt4 installed: False
PySide >= 1.0.3 installed: False
Tried to load: ['pyside', 'pyqt']
I assume the problem is that I have PyQt5 instead of PyQt4. Is this the problem or I have missed some thing else?
Is there anyway that I can have qtconsole with PyQt5? If no, what is the easiest way to do so? (preferably, a method that does not involve having two versions of Qt library on one machine).
For sake of brevity I skipped posting the full error message. Please let me know if I should add them from better understanding of the situation.
The problem might be related to your python path.
I had almost the exact same problem. I had installed PyQt using Homebrew and I was getting the same error message. Finally what solved the problem was adding the following line to my .bash_profile:
export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH
Since I am a beginner myself, I can't help you any further but I hope this solves the problem.
I know this is really old, but I was recently having trouble setting up PyQt5.
The problem was that PyQt5 would install, but some of the sub modules would not. For instance try
import PyQt5 #works
from PyQt5 import * # might fail
If the second command fails, then you have a problem with the PyQt5 setup, and you need to focus on that.
Specifically, ipython+qt will try to import the following
from PyQt5 import QtCore, QtSvg, QtWidgets, QtGui
If any of these sub-modules are broken/missing the qt console launch will quietly fail.
For me it turned out that the PyQt5 installer was failing to make the QtSvg bindings, which ipython tries to load from PyQt5. When you run the configure.py, use the -w option and you will see all the details of the build, allowing you to pinpoint where the install is failing.
In my case, a little googling and I found out that I was missing the QtSvg lib, which can be pulled in easily from the repos.
Setting environment variable QT_API=pyqt5 solved the same problem for me.
I had the same problem, though with the most recent brew of ipython the ImportError included PyQt5 (along with PyQt4 and PySide). So if it didn't work with PyQt5 before, it does now.
Adding the correct PYTHONPATH to .bash_profile fixed it for me, even in my virtualenv. (I don't have the reputation to up-vote or comment on oxtay's answer, where this would be more appropriate...)

Categories