Python3.5+PYQT5:ModuleNotFoundError: No module named 'PyQt5'
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python3.5+PYQT5:ModuleNotFoundError: No module named 'PyQt5'相关的知识,希望对你有一定的参考价值。
python3.5+pycharm+pyqt5使用PyUIC时,报出标题所示错误,如图所示pycharm中,pyuic配置如图系统环境变量配置如图求解~
参考技术A Okay, I hammered at this until I finally found a solution. It seems like this might be a bug in the PyQt library installation or somewhere else. I created a $PYTHONPATH environment variable to point to the newly installed PyQt .py files that hold references to the all of the Qt bindings.export set PYTHONPATH=$PYTHONPATH:/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
After that, everything worked like magic. This includes PyCharm after going to Settings->Project Interpreter->Python Interpreters->Paths (tab), and clicking the "Reload list of paths" button with the blue circular arrows on the bottom.
Python,pyqt5
import sys
import os
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
class Qt_pet(QWidget):
def __init__(self):
super(Qt_pet, self).__init__()
self.dis_file = "img1"
self.windowinit()
self.icon_quit()
self.pos_first = self.pos()
self.img_count = len(os.listdir('./image/'.format(self.dis_file)))
self.timer = QTimer()
self.timer.timeout.connect(self.img_update)
self.timer.start(100)
def img_update(self):
if self.img_num < self.img_count:
self.img_num += 1
else:
self.img_num = 0
self.img_path = './image/file/img.png'.format(file=self.dis_file, img=str(self.img_num))
self.qpixmap = QPixmap(self.img_path)
self.lab.setPixmap(self.qpixmap)
def windowinit(self):
self.x = 1800
self.y = 800
self.setGeometry(self.x, self.y, 300, 300)
self.setWindowTitle('My Pet')
self.img_num = 1
self.img_path = './image/file/img.png'.format(file=self.dis_file, img=str(self.img_num))
self.lab = QLabel(self)
self.qpixmap = QPixmap(self.img_path)
self.lab.setPixmap(self.qpixmap)
self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.SubWindow)
self.setAutoFillBackground(False)
self.setAttribute(Qt.WA_TranslucentBackground, True)
self.show()
def icon_quit(self):
mini_icon = QSystemTrayIcon(self)
mini_icon.setIcon(QIcon('./image/img3/1.png'))
quit_menu = QAction('Exit', self, triggered=self.quit)
tpMenu = QMenu(self)
tpMenu.addAction(quit_menu)
mini_icon.setContextMenu(tpMenu)
mini_icon.show()
def mousePressEvent(self, QMouseEvent):
if QMouseEvent.button() == Qt.LeftButton:
self.pos_first = QMouseEvent.globalPos() - self.pos()
QMouseEvent.accept()
self.setCursor(QCursor(Qt.OpenHandCursor))
def mouseMoveEvent(self, QMouseEvent):
if Qt.LeftButton:
self.move(QMouseEvent.globalPos() - self.pos_first)
print(self.pos())
self.x, self.y = self.pos().x, self.pos().y
QMouseEvent.accept()
def quit(self):
self.close()
sys.exit()
if __name__ == '__main__':
app = QApplication(sys.argv)
pet = Qt_pet()
sys.exit(app.exec_())
谁来帮我解释解释这个,就像第一行是干什么的,第二行或者第一段是干什么的,这个样子
嘿嘿,能多解释一点吗
参考技术B pyqt5-基础 PyQt5是一套来自Digia的Qt5应用框架和Python的粘合剂。支持Python2.x和Python3.x版本。 PyQt5以一套Python模块的形式来实现功能。 参考技术C 这个世界并不缺少「发现美的眼睛」,而是缺少发现「发现美的眼睛」的眼睛 参考技术D import sysfrom PyQt5 import QtWidgets
#创建一个应用(Application)对象,sys.argv参数是一个来自命令行的参数列表,
# Python脚本可以在shell中运行。这是我们用来控制我们应用启动的一种方法。
app = QtWidgets.QApplication(sys.argv)
#创建一个widget组件基础类
windows = QtWidgets.QWidget()
#设置widget组件的大小(w,h)
windows.resize(500,500)
#设置widget组件的位置(x,y)
windows.move(100,100)
"""
#设置widget组件的位置居中
qr = windows.frameGeometry()
cp = QtWidgets.QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
windows.move(qr.topLeft())
"""
#等同于 w.resize(500,500)和w.move(100,100)两句结合,(x,y,w,h)
#windows.setGeometry(100,100,500,500)
#show()方法在屏幕上显示出widget组件
windows.show()
#循环执行窗口触发事件,结束后不留垃圾的退出,不添加的话新建的widget组件就会一闪而过
sys.exit(app.exec_()) 第5个回答 2021-11-15 打开app,然后把定位改到那里,直接搜索,选择一个自己喜欢的
以上是关于Python3.5+PYQT5:ModuleNotFoundError: No module named 'PyQt5'的主要内容,如果未能解决你的问题,请参考以下文章
完美配置Python3.5+Anaconda+PyQt5,实现UI和其他模块的结合
1.Python3.5+Pyqt5+PyCharm+Opencv3.3+Qtdesigner开发环境配置
python3.5 + PyQt5 +Eric6 实现的一个计算器
Python3.5+PyQt5多线程+itchat实现微信防撤回桌面版代码