I am trying to create an icon using QFileIconProvider on PyQt5 on macOs Catalina:
from PyQt5.QtWidgets import QFileIconProvider
ip = QFileIconProvider()
ip.icon(QFileIconProvider.Folder)
the former code yields:
zsh: segmentation fault
I am using python 3.7
How can I solve this?
Many of Qt's objects require a QXApplication to be created, and that's the case for QFileIconProvider:
from PyQt5.QtWidgets import QApplication, QFileIconProvider
app = QApplication([])
ip = QFileIconProvider()
icon = ip.icon(QFileIconProvider.Folder)
print(icon, icon.isNull())
Related
Windows 10 PyCharm Python 3.9.0
I installed PyQt6 and then pyqt6-tools in PyCharm throw the File->Settings.
Now when i run my program i am getting the following error in the terminal
from PyQt6.QtWidgets import QApplication, QWidget
PyQt6: DLL load failed while importing QtGui: The specified procedure could not be found.
My program code
import sys
from PyQt6.QtWidgets import QApplication, QWidget
app = QApplication(sys.args)
window = QWidget()
window.show()
app.exec()
How can i solve this problem?
The following command helped me solve this problem:
pip install --upgrade PyQt6
![My Code][1]
I installed all the libraries using pip and pip3.
I'm using python 3.8.3 and spyder 4.1.4
when ı writing codes IDE show me all libraries in QtWebEngine but trying to start my code IDE says
"module 'PyQt5' has no attribute 'QtWebEngineWidgets'"
and ı have all QtWebEngineWidgets files in computer.
import PyQt5 as py
import sys
app=py.QtWidgets.QApplication(sys.argv)
#app = Py.QApplication(sys.argv)
window = py.QtWidgets.QMainWindow()
window = py.QtWidgets.QWidget()
p=py.QtWebEngineWidgets.QWebEngineView(window)
b=py.QtCore.QUrl('https://stackoverflow.com')
p.load(b)
p.show()
window.setGeometry(0, 35, 400, 400)
window.setWindowTitle("Ground Control")
window.show()
app.exec_()
from PyQt5 import QtWidgets, QtWebEngineWidgets
pop this in and this should get you further
I am using PyCharm 2020.2 and I can't access PyQt5. From the Python interpreter it is showing PyQt5 ver 5.15.0. when I run this simple code
import sys
from PyQt5.QtWidgets import QApplication, QWidget
app = QApplication(sys.argv)
window = QWidget()
window.show()
app.exec_()
I am getting the following error: ModuleNotFoundError: No module named 'PyQt5'
I have no idea where to go next.
I'm just starting out writing a program with the PyQt5 gui framework. I have a file, resource_loader.py, which is responsible for loading images etc.
The problem
Python crashes at the line where the image is loaded. I'm using IDLE (3.5) and after I run the program there is no output except for:
=============================== RESTART: Shell ===============================
Code - pretty much copy/pasted from a tutorial, file is called resource_loader.py
from PyQt5 import QtGui
import os
file_image = QtGui.QPixmap("file.png")
Things I've tried
file.png definitely is in the same directory as resource_loader.py
Changing up the variable names, just in case.
Moving the file to a location with no spaces in the path
Extra information
I am running resource_loader.py directly
I am using Linux Mint (18.3) Xfce if that's any use.
Thanks in advance.
It is required to place your code within a QApplication instance as follows:
import sys
import os
from PyQt5 import QtGui
from PyQt5.QtWidgets import (QApplication, QWidget)
app = QApplication(sys.argv)
file_image = QtGui.QPixmap("file.png")
sys.exit(app.exec_())
I installed PyQt5 with conda this way: conda install -c inso pyqt5=5.6. I have python 3.5. When I run a simple program that uses PyQt5, the program gets stuck on PyQt5 import and there is no error message. It gets stuck for about 5 seconds, then the program just terminates. See the example below that I found on google. The program gets stuck on the line from PyQt5.QtWidgets import QApplication, QWidget. I can see the packcage in C:\Users\user\Anaconda3\Lib\site-packages\PyQt5. What might be causing suck a behavior?
"""
ZetCode PyQt5 tutorial
In this example, we create a simple
window in PyQt5.
author: Jan Bodnar
website: zetcode.com
last edited: January 2015
"""
import sys
from PyQt5.QtWidgets import QApplication, QWidget
app = QApplication(sys.argv)
w = QWidget()
w.resize(250, 150)
w.move(300, 300)
w.setWindowTitle('Simple')
w.show()
sys.exit(app.exec_())
First comment here solved my problem. DLL load failed when importing PyQt5
I uninstalled pyqt5 and reinstalled wtih conda install --channel https://conda.anaconda.org/bpentz pyqt5