僅供參考,需要根據(jù)自己實際修改
?。?!arm 架構(gòu)建議直接使用pyqt6,不折騰pyqt5
pyqt6安裝參考
PyQT6:看這一篇就夠了
python PyQt6 常用操作以及常見問題解決 pycharm配置tools
一 pip安裝 轉(zhuǎn)義安裝
參考鏈接
# 一條代碼就可以搞定沒錯,使用的是Rosetta2 x86_64模式安裝的
arch -x86_64 python3 -m pip install PyQt5
arch -x86_64 python3 -m pip install pyqt5-tools
二 brew安裝 arm版
以下pip命令自行更具自己環(huán)境選擇pip或pip3
在安裝pyqt前必須先安裝sip包
pip3 install sip
完成sip的安裝后,安裝pyqt和pyqt-tools,
可以直接使用命令:
pip3 install PyQt5
pip3 install PyQt5-tools
若是使用pip3安裝報錯
AttributeError: module ‘sipbuild.api’ has no attribute ‘prepare_metadata_for_build_wheel’
解決方法:
通過brew安裝pyqt5,再將相關(guān)文件拷貝至虛擬環(huán)境(如果需要)
brew install pyqt@5
如果你沒有安裝brew,需要在終端輸入下行代碼進(jìn)行安裝。
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
若還是報錯;如下:
==> Installing dependencies for pyqt@5: qt@5
==> Installing pyqt@5 dependency: qt@5
==> Pouring qt@5-5.15.5_1.arm64_monterey.bottle.tar.gz
Error: No such file or directory @ rb_sysopen
根據(jù)提示
用brew單獨下載依賴包,就避免了找不到依賴版本的錯誤
brew install qt@5
然后在執(zhí)行
brew install pyqt@5
直到pyqt安裝成功
安裝完成后,打開路徑/opt/homebrew/Cellar/pyqt@5/5.15.7_1/lib/python3.9/site-packages,如下圖
將文件全部拷貝下來,粘貼至/Users/your_name/miniforge3/envs/你的虛擬環(huán)境名/lib/python3.9/site-packages ,或者
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages 具體路徑因人而異。
測試
import sys
from PyQt5 import QtCore, QtGui, QtWidgets #導(dǎo)入PyQt5包中的幾個模塊
app = QtWidgets.QApplication(sys.argv) #創(chuàng)建App,用QApplication類
widgetHello = QtWidgets.QWidget() #創(chuàng)建一個窗體widgetHello,用QWidget類
widgetHello.resize(280,150) #設(shè)置對話框的寬度和高度
widgetHello.setWindowTitle("Demo2_1") #設(shè)置對話框的標(biāo)題文字
LabHello = QtWidgets.QLabel(widgetHello) #創(chuàng)建一個標(biāo)簽LabHello,父容器為widgetHello
LabHello.setText("Hello World, PyQt5") #設(shè)置標(biāo)簽文字
font = QtGui.QFont() #創(chuàng)建字體對象font,用QFont類
font.setPointSize(12) #設(shè)置字體大小
font.setBold(True) #設(shè)置為粗體
LabHello.setFont(font) #設(shè)置為標(biāo)簽LabHello的字體
size=LabHello.sizeHint() #獲取LabHello的合適大小,返回值aLabSize是QSize類對象
LabHello.setGeometry(70, 60, size.width(), size.height())
##設(shè)置LabHello的位置和大小,位置x=70,y=60, 寬度和高度由aLabSize的值確定
widgetHello.show() #顯示對話框
sys.exit(app.exec_()) #應(yīng)用程序運行
pycharm配置
brew qt designer位置
轉(zhuǎn)義安裝 designer位置
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/qt5_applications/Qt/bin
配置QtDesigner
主要用來設(shè)計軟件界面,并保存為.ui文件。
在 File - Settings 設(shè)置界面,按圖操作。注意 步驟 2是選擇上圖qt designer位置,文件夾內(nèi)的 designer。步驟3輸入的是 $ProjectFileDir$ 。
PyUIC位置
和配置 QtDesigner類似。
Program:選擇python的安裝位置
Arguments:輸入 -m PyQt5.uic.pyuic $FileName$ -o $FileNameWithoutExtension$.py文章來源:http://www.zghlxwxcb.cn/news/detail-621272.html
Working :輸入 $FileDir$文章來源地址http://www.zghlxwxcb.cn/news/detail-621272.html
到了這里,關(guān)于mac python3.9安裝pyqt5、qt5、pyqt5-tools的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!