PyQt5 Maya 2017 - python

Having some trouble setting up PyQt5 with Maya 2017. I have successfully installed PyQt5 on my mac and I can write standalone applications, but when I try to import PyQt5 modules in the Maya Script Editor using (for example)
from PyQt5 import QtWidgets
I get the following error :
Error: line 1: ImportError: file <maya console> line 1: No module named PyQt5
Not very experienced with using Python in Maya, is there some configuration I have to do? Also, does PyQt5 work with Maya 2016?

Maya won't ship with pyqt and you need to build your own version of pyqt for maya with mayapy. You local install of pyqt won't get loaded to maya so need to compile your version yourself. This link will give a insight of that http://justinfx.com/2011/11/09/installing-pyqt4-for-maya-2012-osx/. Although maya 2017 shipping with PySide2 and you can always use Pyside rather than pyqt.
like
from PySide2 import QtWidgets
Hope this helps.

If you want your scripts and UIs to work on either Maya 2016 or 2017 and above, I would suggest using the Qt.py package from Marcus Ottoson.
You can find it here.
You can just install it somewhere on your computer and add its path to the 'path' variable in your environment variables, you can then just do:
from Qt import QtWidgets, QtCore, QtGui
You can then write your UIs as you would in PySide2, and they will work on all versions of Maya because Qt.py is just a wrapper choosing the proper binding available on your machine, whether it is Pyside, Pyside2, Qt5, Qt4.

Related

Unable to import QtGui, QtWidgets modules of PyQt5/PySide in WinPE

I'm developing a tool to be used in WinPE and have been facing an issue while using PySide2/PyQt5 in WinPE environment.
While importing QtGui, it says ImportError: DLL load failed while importing QtGui: The specified module could not be found.
But importing QtCore is successful.
If I use the same environment in another Windows machine it is successful.
I also developing a pyqt5 program run in winpe.
using pyinstaller convert it to exe and run successfully in a new win7 machchine.
when start at win10 pe the command line says below message.
The specified module could not be found.
I found one solution is using specific version of PyQT5 from below url
pip install PyQT5==5.9
https://stackoverflow.com/a/51821319/7324168

Using PyQt4 & sip for shared maya script - how to set up modules?

I want to use PyQt4 and sip in a shared maya script. I figured I can't use pip-install because I would only get these modules locally on my machine. I manually extracted these folders into my script directory. I can import both PyQt4 and sip but I can't run any commands from the modules "QtGui, QtCore" and so on. Is it possible to do it this way or do I have to install these modules? If so what is another solution to use PyQt4 in a shared script?
Here are some import scripts I tried:
import sys
from python_modules.sip import *
from python_modules.PyQt4 import *
app = QtGui.QApplication(sys.argv)
Gives error:
'module' object has no attribute 'QApplication'
I Also added _.init._.py to python_libraries, sip & PyQt4 folders.
For every version of maya, there is a page in around the corner explaining how to install PyQt for maya as maya is using a custom python package "mayapy", the install is a bit painfulbut...
around the corner
Also, it has been few versions of maya which embbed PySide, it might be easier than installing PyQt on every machine depending of your privileges.
PyQt is not just a simple python module, but a binding (usually requires to be installed to work as expected).
While theoretically it could be possible to "copy" all the needed files, you would probably always face some issues, expecially if the Qt version doesn't match (possibly for different Maya versions) or different OSs are used.
So, it's better to install PyQt on every machine, maybe using a script.

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

PyQt5 crashes if I import QtWebEngineWidgets

I created a new Anaconda environment with Python 3.6. I installed PyQt5 with pip install PyQt5. I have this butt-simple program:
from PyQt5 import QtWidgets
#from PyQt5 import QtWebEngineWidgets
app = QtWidgets.QApplication([])
As written, it runs (and does nothing). If I uncomment the QtWebEngineWidgets line, it crashes. If I leave that line uncommented, but comment out the final line, it no longer crashes. In other words, it crashes when trying to create the application, but only if I previously tried to import QtWebEngineWidgets. Importing QtWebEngineWidgets itself doesn't cause a crash unless I try to create an application.
I'm running this on Windows 7. The crash is a "hard" crash: it's not a Python exception, but a Windows popup saying "Python has stopped working". The info says that the crash is in "atio6axx.dll". Googling around I see some hints that there could be some sort of conflict between Qt and my graphics driver, but I don't know how to debug it, let alone fix it. (I have an embedded graphics controller that shows as ATI Radeon HD 4250.)
conda list qt shows:
PyQt5 5.8.2 <pip>
What can I do to be able to use QtWebEngine successfully?
In my experience this issue has nothing to do with PyQt being installed using both pip and anaconda, although this would cause an problem too. If you only have pyqt installed on Anaconda the following code my cause a hard crash:
from qtpy import QtWidgets
from qtpy import QtWebEngineWidgets
app = QtWidgets.QApplication([])
We started experiencing this on a number of computers after an "upgrade" to windows 10, and noticing Spyder stopped working. It exited without an error message. The IT guys tracked it down to the graphics card.
Solutions: downgrade pyqt to version 5.6: conda install pyqt=5.6
I'm seeing this behavior on a windows 10 machine currently as well.
I use qtpy as well but have done this same example in just PyQt5.
Downgraded to 5.6 changes other behavior li

Categories