筆記:搭建pyQT5開發環境(Python3 +PyCharm 2018 +PyQt5)


安裝環境

win7  64位
Python 3.7.5
PyCharm 2018 社區版

pip list 列出當前已經安裝的第三方Python包

安裝 PyQt5

  cmd  中輸入(管理員模式)
pip install PyQt5
或通過鏡像站資源安裝
清華:https://pypi.tuna.tsinghua.edu.cn/simple
阿里雲:http://mirrors.aliyun.com/pypi/simple/
中國科技大學:https://pypi.mirrors.ustc.edu.cn/simple/
華中理工大學:http://pypi.hustunique.com/
山東理工大學:http://pypi.sdutlinux.org/
豆瓣:http://pypi.douban.com/simple/
 cmd 中進入 python3 交互環境 import PyQt5 沒有報錯,說明安裝成功

安裝pyqt5-tools

  cmd  中輸入
pip install pyqt5-tools
pip install PyQt5-tools -i https://mirrors.aliyun.com/pypi/simple
安裝好后 在你 python 的安裝目錄下 \ib\site-packages\pyqt5-tools\designer.exe 雙擊 designer.exe 就可以啟動該軟件
安裝完成后,將安裝目錄添加到系統環境變量
如 C:\Python36\Lib\site-packages\pyqt5-tools
說明:在舊版本的 PyQt5 .whl 文件中,會包含諸如 Qt Designer 等工具。
但是在最新版本的 .whl 文件中不再提供這些工具,會更加專注於實現 PyQt5 應用程序的依賴。相關的工具轉而由 PyQt5-tools 提供,比如 Qt Designer。一旦安裝了 PyQt5-tools 便可不再安裝 Qt 開發工具

pip list  列出當前已經安裝的第三方Python包


配置PyCharm 

配置PyCharm是為了在Pycharm里面實現打開qt designer,然后生成qt文件,然后將qt文件轉換成python語言的軟件文件

打開設置,添加外部工具

添加QtDesigner

新版的designer.exe放在\Lib\site-packages\pyqt5_tools\Qt\bin下

添加PyUIC

Arguments: $FileName $ -o $FileNameWithoutExtension$_rc.py


PyInstaller安裝

pip3 install pyinstaller

打包命令:cmd控制台到F:\Python 3.5\Scripts路徑下,輸入命令 pyinstaller.exe -F f:\prj\hello.py,
即可生成一個hello.exe獨立的執行文件;不使用-F命令將會一同生成依賴庫


遇到的問題總結
0. CMD命令權限問題
右鍵-管理員模式啟動CMD命令行,否則可能出現安裝程序無法寫法本地目錄的情況

1.安裝問題
使用pip install PyQt5pip install pyqt5-tools命令
可能因延遲過高導致安裝失敗,可以嘗試使用鏡像站資源
pip install PyQt5 -i https://mirrors.aliyun.com/pypi/simple
pip install PyQt5-tools -i https://mirrors.aliyun.com/pypi/simple

2.無法安裝PyQt5-tools,顯示無可用版本
會出現下面的錯誤:
Collecting pyqt5-tools
  Could not find a version that satisfies the requirement pyqt5-tools (from versions: )
No matching distribution found for pyqt5-tools

2019年10月,測試Python 3.8 穩定版本,無法安裝pyqt5 tools
卸載Python 3.8 ,重新安裝Python 3.7.5 穩定版,可安裝pyqt5 tools 

3.配置 PyCharm 
調用外部工具QtDesigner,出現錯誤
ModuleNotFoundError: No module named 'PyQt5'
(安裝的PyQt5包未加入PyCharm項目解釋器)
解決方法:
新建工程時,勾選

對於已存在工程
在已有項目的最后面找到External Libraries ,然后找到venv目錄,把pyvenv.cfg文件中的如下參數改成true
include-system-site-packages = true

調用PyUIC,出現錯誤
No such file or directory
one input ui-file must be specified
解決方法:
1.轉換ui文件時,先選中ui文件,然后再調用PyUIC工具
2.ui文件命令中不能有空格


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM