PyQt5:使用 VS Code 來開發 PyQt 的 GUI 程式
上次裝了 Eric6 的 IDE 工具,但最近太常在 VS Code 寫東西,不得不說這東西真的很好用,乾脆也看看 PyQt 能不能整合進 VS Code,發現到它的外掛模組就有我要的功能,想當然就是直接裝來試試看,個人覺得比 Eric6 跟 PyCharm 好用很多,需要設定的東西也差不多,就來看看怎麼裝吧。
Install Python interpreter
我是安裝 Anaconda 來建立整個 Python 環境
我習慣裝在 C 槽 C:\Anaconda3\
加入環境變數
conda create -n pyqt python=3.7
activate pyqt
Install PyQt5 Package
主要寫程式需要的是 PyQt5,但是為了搭配 Qt designer,所以我會先裝 pyqt5_tools,然後再裝 PyQt5,通常在裝 pyqt5_tools 時,就會自動下載 PyQt5 對應的版本。
- PyQt5:主要的套件
- pyqt5_tools:各種 Qt 相關工具,但我目前只用到 designer.exe
pip install pyqt5_tools
pip install PyQt5
Install extension
- Python
- PyQt5 integration
VS Code Setup
第一次在資料夾管理器 (Explorer) 或是工作區,按右鍵選擇 "PYQT:New Form",然後由於還沒設路徑所以會出現 Error。
- 設定 > 延伸模組 > PYQT integration configuration > Qtdesigner: Path
(Qt designer 用來拉 GUI 用的)
設定路徑
c:\Anaconda3\envs\arduino\Lib\site-packages\qt5_applications\Qt\bin\designer.exe
- 設定 > 延伸模組 > PYQT integration configuration > Pyuic: Cmd
(這是用來把 *.ui 檔轉成 *.py 檔)
設定路徑
C:\Anaconda3\envs\arduino\Scripts\pyuic5
到這邊就都設好了。
Update:2021/05/17
上面路徑是根據我的 Anacoda 路徑下去找的,如果是直接預設的路徑、不同虛擬環境名稱以及直接裝 Python 的人,應該都會跟我的路徑不一樣,這點要注意。
以設定 Qt Designer 為例:
- 我的 Anaconda 是直接裝 C 槽底下
(C:\Anaconda3) - 我有開虛擬環境,名稱為 arduino
(C:\Anaconda3\envs\arduino) -
要找到 Qt Designer,必須去 Lib\site-packages\ 底下才行
(C:\Anaconda3\envs\arduino\Lib\site-packages) -
去找 pyqt5_tools 的工具,它在 qt5_applications\Qt\bin\ 裡面
(c:\Anaconda3\envs\arduino\Lib\site-packages\qt5_applications\Qt\bin) -
最後,找到 designer.exe
(c:\Anaconda3\envs\arduino\Lib\site-packages\qt5_applications\Qt\bin\designer.exe)
那另外一個 pyuic5 就是去你安裝 Python 的地方 (或是你的 Conda 虛擬環境),找到 Scripts 這個資料夾,然後找到 pyuic5,就行了
2 則留言
Jessica Hoddle
You have 1 unread message from a LOCAL admirer!
Click now to uncover their identity and claim your FREE access to flirt instantly:
https://free-dating.club/
Don’t keep them waiting…
YouTube Downloader for PC
Hello, I won’t waste your time—here’s the point:
Millions of people want to download their favorite YouTube videos and tunes but haven’t found a reliable website or app that does it without ads or viruses.
That’s why I built a minimalistic YouTube downloader for Windows, complete with all the essential features for effortless downloads.
Try my app, and I hope you’ll be 100% satisfied.
Download it here: https://youtubedownloaderforpc.com
P.S. The main goal behind launching this app is to eliminate spam ads and viruses, helping to keep the internet safe. If you like the app, please share it with your friends. If this message isn’t relevant to you, please ignore it, and I promise you won’t receive another email from me about it. Thanks for your understanding.