開始是準備安裝PYQT5的,但是安裝不下去,就改成安裝PYQT6
一.安裝pyqt5,成功。
c:\PYQT>pip install pyqt5
Defaulting to user installation because normal site-packages is not writeable
Collecting pyqt5
? Downloading PyQt5-5.15.11-cp38-abi3-win_amd64.whl.metadata (2.1 kB)
Collecting PyQt5-sip<13,>=12.15 (from pyqt5)
? Downloading PyQt5_sip-12.17.0-cp313-cp313-win_amd64.whl.metadata (492 bytes)
Collecting PyQt5-Qt5<5.16.0,>=5.15.2 (from pyqt5)
? Downloading PyQt5_Qt5-5.15.2-py3-none-win_amd64.whl.metadata (552 bytes)
Downloading PyQt5-5.15.11-cp38-abi3-win_amd64.whl (6.9 MB)
? ?---------------------------------------- 6.9/6.9 MB 8.1 MB/s eta 0:00:00
Downloading PyQt5_Qt5-5.15.2-py3-none-win_amd64.whl (50.1 MB)
? ?---------------------------------------- 50.1/50.1 MB 9.0 MB/s eta 0:00:00
Downloading PyQt5_sip-12.17.0-cp313-cp313-win_amd64.whl (58 kB)
Installing collected packages: PyQt5-Qt5, PyQt5-sip, pyqt5
二.安裝 pyqt5-tools,失敗
c:\PYQT>pip install pyqt5-tools
Defaulting to user installation because normal site-packages is not writeable
Collecting pyqt5-tools
? Using cached pyqt5_tools-5.15.9.3.3-py3-none-any.whl.metadata (8.3 kB)
Collecting click (from pyqt5-tools)
? Using cached click-8.1.8-py3-none-any.whl.metadata (2.3 kB)
Collecting pyqt5==5.15.9 (from pyqt5-tools)
? Using cached PyQt5-5.15.9-cp37-abi3-win_amd64.whl.metadata (2.2 kB)
INFO: pip is looking at multiple versions of pyqt5-tools to determine which version is compatible with other requirements. This could take a while.
Collecting pyqt5-tools
? Using cached pyqt5_tools-5.15.4.3.2-py3-none-any.whl.metadata (8.3 kB)
Collecting pyqt5==5.15.4 (from pyqt5-tools)
? Using cached PyQt5-5.15.4.tar.gz (3.3 MB)
? Installing build dependencies ... done
? Getting requirements to build wheel ... done
? Preparing metadata (pyproject.toml) ... error
? error: subprocess-exited-with-error
? × Preparing metadata (pyproject.toml) did not run successfully.
? │ exit code: 1
? ╰─> [32 lines of output]
?raise PyProjectOptionException('qmake', ? ? ? ? ? ? ? ? ?"specify a working qmake or add it to PATH")
? ? ? sipbuild.pyproject.PyProjectOptionException
因為我的python版本太高,但是降到低版本也失敗
c:\PYQT>python -V
Python 3.13.2
c:\PYQT>pip install python==3.9.0
Defaulting to user installation because normal site-packages is not writeable
ERROR: Could not find a version that satisfies the requirement python==3.9 (from versions: none)
ERROR: No matching distribution found for python==3.9.0
去https://www.python.org/downloads/windows/ 上面沒有找到3.9版本的下載包
三.既然如此,安裝pyqty6
c:\PYQT>pip install pyqt6
Defaulting to user installation because normal site-packages is not writeable
Collecting pyqt6
? Downloading PyQt6-6.8.1-cp39-abi3-win_amd64.whl.metadata (2.1 kB)
Collecting PyQt6-sip<14,>=13.8 (from pyqt6)
? Downloading PyQt6_sip-13.10.0-cp313-cp313-win_amd64.whl.metadata (492 bytes)
Collecting PyQt6-Qt6<6.9.0,>=6.8.0 (from pyqt6)
? Downloading PyQt6_Qt6-6.8.2-py3-none-win_amd64.whl.metadata (551 bytes)
Downloading PyQt6-6.8.1-cp39-abi3-win_amd64.whl (6.7 MB)
? ?---------------------------------------- 6.7/6.7 MB 7.5 MB/s eta 0:00:00
Downloading PyQt6_Qt6-6.8.2-py3-none-win_amd64.whl (71.9 MB)
? ?---------------------------------------- 71.9/71.9 MB 7.3 MB/s eta 0:00:00
Downloading PyQt6_sip-13.10.0-cp313-cp313-win_amd64.whl (53 kB)
Installing collected packages: PyQt6-Qt6, PyQt6-sip, pyqt6
ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: 'C:\\Users\\admin\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python313\\site-packages\\PyQt6\\Qt6\\qml\\QtQuick\\Controls\\FluentWinUI3\\dark\\images\\editablecombobox-popup-background-hovered-open@2x.png'
Solution 1: Package Installation with --user Option
原因是but still limited the maximum path length (which includes the full folder path and the file name) to 260 characters
修改注冊表
計算機\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem ,LongPathsEnabled的0改成1
c:\PYQT>pip install --user pyqt6
Collecting pyqt6
? Using cached PyQt6-6.8.1-cp39-abi3-win_amd64.whl.metadata (2.1 kB)
Collecting PyQt6-sip<14,>=13.8 (from pyqt6)
? Using cached PyQt6_sip-13.10.0-cp313-cp313-win_amd64.whl.metadata (492 bytes)
Collecting PyQt6-Qt6<6.9.0,>=6.8.0 (from pyqt6)
? Using cached PyQt6_Qt6-6.8.2-py3-none-win_amd64.whl.metadata (551 bytes)
Using cached PyQt6-6.8.1-cp39-abi3-win_amd64.whl (6.7 MB)
Using cached PyQt6_Qt6-6.8.2-py3-none-win_amd64.whl (71.9 MB)
Using cached PyQt6_sip-13.10.0-cp313-cp313-win_amd64.whl (53 kB)
Installing collected packages: PyQt6-Qt6, PyQt6-sip, pyqt6
? WARNING: The scripts pylupdate6.exe and pyuic6.exe are installed in 'C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\Scripts' which is not on PATH.
? Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed PyQt6-Qt6-6.8.2 PyQt6-sip-13.10.0 pyqt6-6.8.1
四.安裝pyqty6-plugins插件
c:\PYQT>pip install pyqt6-plugins
Defaulting to user installation because normal site-packages is not writeable
ERROR: Could not find a version that satisfies the requirement pyqt6-plugins (from versions: none)
ERROR: No matching distribution found for pyqt6-plugins
但是pyqt6-plugins不支持python 3.12的pip安裝,所以無法使用pip簡單安裝,查了別人的方案,還是停麻煩的。
a.https://pypi.org/project/pyqt6-plugins/#files 下載最新版本
b.用winrar打開修改里面的medata文件,將Requires-Dist: pyqt6后面的版本號限制去掉
Requires-Dist: pyqt6
Requires-Dist: pyqt6-qt6 (==6.4.3)
Requires-Dist: qt6-tools (<6.4.3.2,>=6.4.3.1.2)
c.將修改號的文件拷貝到安裝目錄下,安裝
c:\PYQT>pip install pyqt6_plugins-6.4.2.2.3-cp311-cp311-win_amd64.whl
Defaulting to user installation because normal site-packages is not writeable
ERROR: pyqt6_plugins-6.4.2.2.3-cp311-cp311-win_amd64.whl is not a supported wheel on this platform.
原因是除了修版本顯示還不行,還需要修改文件名,修改后再次安裝
c:\PYQT>pip install pyqt6_plugins-6.4.2.2.3-py3-none-any.whl
Defaulting to user installation because normal site-packages is not writeable
Processing c:\pyqt\pyqt6_plugins-6.4.2.2.3-py3-none-any.whl
Collecting click (from pyqt6-plugins==6.4.2.2.3)
? Using cached click-8.1.8-py3-none-any.whl.metadata (2.3 kB)
Requirement already satisfied: pyqt6 in c:\users\admin\appdata\local\packages\pythonsoftwarefoundation.python.3.13_qbz5n2kfra8p0\localcache\local-packages\python313\site-packages (from pyqt6-plugins==6.4.2.2.3) (6.8.1)
Collecting pyqt6-qt6==6.4.3 (from pyqt6-plugins==6.4.2.2.3)
? Downloading PyQt6_Qt6-6.4.3-py3-none-win_amd64.whl.metadata (551 bytes)
Collecting qt6-tools<6.4.3.2,>=6.4.3.1.2 (from pyqt6-plugins==6.4.2.2.3)
? Downloading qt6_tools-6.4.3.1.3-py3-none-any.whl.metadata (1.9 kB)
Collecting qt6-applications<6.4.3.3,>=6.4.3.2.2 (from qt6-tools<6.4.3.2,>=6.4.3.1.2->pyqt6-plugins==6.4.2.2.3)
? Downloading qt6_applications-6.4.3.2.3-py3-none-win_amd64.whl.metadata (2.2 kB)
Collecting colorama (from click->pyqt6-plugins==6.4.2.2.3)
? Downloading colorama-0.4.6-py2.py3-none-any.whl.metadata (17 kB)
Requirement already satisfied: PyQt6-sip<14,>=13.8 in c:\users\admin\appdata\local\packages\pythonsoftwarefoundation.python.3.13_qbz5n2kfra8p0\localcache\local-packages\python313\site-packages (from pyqt6->pyqt6-plugins==6.4.2.2.3) (13.10.0)
INFO: pip is looking at multiple versions of pyqt6 to determine which version is compatible with other requirements. This could take a while.
Collecting pyqt6 (from pyqt6-plugins==6.4.2.2.3)
? Using cached PyQt6-6.8.0-cp39-abi3-win_amd64.whl.metadata (2.1 kB)
? Downloading PyQt6-6.7.1-cp38-abi3-win_amd64.whl.metadata (2.1 kB)
? Downloading PyQt6-6.7.0-1-cp38-abi3-win_amd64.whl.metadata (2.1 kB)
? Downloading PyQt6-6.6.1-cp38-abi3-win_amd64.whl.metadata (2.2 kB)
? Downloading PyQt6-6.6.0-cp37-abi3-win_amd64.whl.metadata (2.2 kB)
? Downloading PyQt6-6.5.3-cp37-abi3-win_amd64.whl.metadata (2.2 kB)
? Downloading PyQt6-6.5.2-cp37-abi3-win_amd64.whl.metadata (2.2 kB)
INFO: pip is still looking at multiple versions of pyqt6 to determine which version is compatible with other requirements. This could take a while.
? Downloading PyQt6-6.5.1-cp37-abi3-win_amd64.whl.metadata (2.2 kB)
? Downloading PyQt6-6.5.0-1-cp37-abi3-win_amd64.whl.metadata (2.2 kB)
? Using cached PyQt6-6.4.2-cp37-abi3-win_amd64.whl.metadata (2.2 kB)
Downloading PyQt6_Qt6-6.4.3-py3-none-win_amd64.whl (57.5 MB)
? ?---------------------------------------- 57.5/57.5 MB 6.9 MB/s eta 0:00:00
Downloading qt6_tools-6.4.3.1.3-py3-none-any.whl (13 kB)
Downloading click-8.1.8-py3-none-any.whl (98 kB)
Downloading PyQt6-6.4.2-cp37-abi3-win_amd64.whl (6.4 MB)
? ?---------------------------------------- 6.4/6.4 MB 9.2 MB/s eta 0:00:00
Downloading qt6_applications-6.4.3.2.3-py3-none-win_amd64.whl (71.3 MB)
? ?---------------------------------------- 71.3/71.3 MB 8.6 MB/s eta 0:00:00
Downloading colorama-0.4.6-py2.py3-none-any.whl (25 kB)
Installing collected packages: pyqt6-qt6, qt6-applications, pyqt6, colorama, click, qt6-tools, pyqt6-plugins
? Attempting uninstall: pyqt6-qt6
? ? Found existing installation: PyQt6-Qt6 6.8.2
? ? Uninstalling PyQt6-Qt6-6.8.2:
? ? ? Successfully uninstalled PyQt6-Qt6-6.8.2
? Attempting uninstall: pyqt6
? ? Found existing installation: PyQt6 6.8.1
? ? Uninstalling PyQt6-6.8.1:
? ? ? Successfully uninstalled PyQt6-6.8.1
? WARNING: The scripts pylupdate6.exe and pyuic6.exe are installed in 'C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\Scripts' which is not on PATH.
? Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
? WARNING: The script qt6-tools.exe is installed in 'C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\Scripts' which is not on PATH.
? Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed click-8.1.8 colorama-0.4.6 pyqt6-6.4.2 pyqt6-plugins-6.4.2.2.3 pyqt6-qt6-6.4.3 qt6-applications-6.4.3.2.3 qt6-tools-6.4.3.1.3
五.安裝pyqt6-tools
c:\PYQT>pip install pyqt6-tools
Defaulting to user installation because normal site-packages is not writeable
Collecting pyqt6-tools
? Using cached pyqt6_tools-6.4.2.3.3-py3-none-any.whl.metadata (8.3 kB)
Requirement already satisfied: click in c:\users\admin\appdata\local\packages\pythonsoftwarefoundation.python.3.13_qbz5n2kfra8p0\localcache\local-packages\python313\site-packages (from pyqt6-tools) (8.1.8)
Requirement already satisfied: pyqt6==6.4.2 in c:\users\admin\appdata\local\packages\pythonsoftwarefoundation.python.3.13_qbz5n2kfra8p0\localcache\local-packages\python313\site-packages (from pyqt6-tools) (6.4.2)
Requirement already satisfied: pyqt6-plugins<6.4.2.3,>=6.4.2.2.2 in c:\users\admin\appdata\local\packages\pythonsoftwarefoundation.python.3.13_qbz5n2kfra8p0\localcache\local-packages\python313\site-packages (from pyqt6-tools) (6.4.2.2.3)
Collecting python-dotenv (from pyqt6-tools)
? Downloading python_dotenv-1.0.1-py3-none-any.whl.metadata (23 kB)
Requirement already satisfied: PyQt6-sip<14,>=13.4 in c:\users\admin\appdata\local\packages\pythonsoftwarefoundation.python.3.13_qbz5n2kfra8p0\localcache\local-packages\python313\site-packages (from pyqt6==6.4.2->pyqt6-tools) (13.10.0)
Requirement already satisfied: PyQt6-Qt6>=6.4.0 in c:\users\admin\appdata\local\packages\pythonsoftwarefoundation.python.3.13_qbz5n2kfra8p0\localcache\local-packages\python313\site-packages (from pyqt6==6.4.2->pyqt6-tools) (6.4.3)
Requirement already satisfied: qt6-tools<6.4.3.2,>=6.4.3.1.2 in c:\users\admin\appdata\local\packages\pythonsoftwarefoundation.python.3.13_qbz5n2kfra8p0\localcache\local-packages\python313\site-packages (from pyqt6-plugins<6.4.2.3,>=6.4.2.2.2->pyqt6-tools) (6.4.3.1.3)
Requirement already satisfied: colorama in c:\users\admin\appdata\local\packages\pythonsoftwarefoundation.python.3.13_qbz5n2kfra8p0\localcache\local-packages\python313\site-packages (from click->pyqt6-tools) (0.4.6)
Requirement already satisfied: qt6-applications<6.4.3.3,>=6.4.3.2.2 in c:\users\admin\appdata\local\packages\pythonsoftwarefoundation.python.3.13_qbz5n2kfra8p0\localcache\local-packages\python313\site-packages (from qt6-tools<6.4.3.2,>=6.4.3.1.2->pyqt6-plugins<6.4.2.3,>=6.4.2.2.2->pyqt6-tools) (6.4.3.2.3)
Downloading pyqt6_tools-6.4.2.3.3-py3-none-any.whl (29 kB)
Downloading python_dotenv-1.0.1-py3-none-any.whl (19 kB)
Installing collected packages: python-dotenv, pyqt6-tools
? WARNING: The script dotenv.exe is installed in 'C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\Scripts' which is not on PATH.
? Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
? WARNING: The script pyqt6-tools.exe is installed in 'C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\Scripts' which is not on PATH.
? Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pyqt6-tools-6.4.2.3.3 python-dotenv-1.0.1
六.安裝成功后,找到兩個路徑,這兩個路徑在vscode中pyqt integration設置中要用到
c:\users\admin\appdata\local\packages\pythonsoftwarefoundation.python.3.13_qbz5n2kfra8p0\localcache\local-packages\python313\site-packages
C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\qt6_applications\Qt\bin
七.打開VSCODE,在插件中安裝pyqt integration,安裝后設置路徑
Pyqt-integration ? Pyuic: Cmd
'pyuic' command file, you can also specify a path
Pyqt-integration ? Qtdesigner: Path
Path of QT designer
八.調整安裝路徑和重新安裝
在Vscode中創建一個文件,右鍵用PYQT:New Form打開,就可以使用設計圖形界面了。
可能會遇到錯誤,主要還是pyqt integration設置中的路徑問題。
Error: Command failed: "C:\Users\admin\appdata\local\packages\pythonsoftwarefoundation.python.3.13_qbz5n2kfra8p0\localcache\local-packages\python313\site-packages\qt6_applications\Qt\bin"
'"C:\Users\admin\appdata\local\packages\pythonsoftwarefoundation.python.3.13_qbz5n2kfra8p0\localcache\local-packages\python313\site-packages\qt6_applications\Qt\bin"'?
??
為什么我的安裝路徑這么深,我需要重裝一遍
c:\PYQT>python -m site
sys.path = [
? ? 'c:\\PYQT',
? ? 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.13_3.13.752.0_x64__qbz5n2kfra8p0\\python313.zip',
? ? 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.13_3.13.752.0_x64__qbz5n2kfra8p0\\DLLs',
? ? 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.13_3.13.752.0_x64__qbz5n2kfra8p0\\Lib',
? ? 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.13_3.13.752.0_x64__qbz5n2kfra8p0',
? ? 'C:\\Users\\admin\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python313\\site-packages',
? ? 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.13_3.13.752.0_x64__qbz5n2kfra8p0\\Lib\\site-packages',
]
USER_BASE: 'C:\\Users\\admin\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\\LocalCache\\local-packages' (exists)
USER_SITE: 'C:\\Users\\admin\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python313\\site-packages' (exists)
ENABLE_USER_SITE: True
新建環境變量PYTHONUSERBASE,然后再次執行,可以看到路徑變了。
C:\PYQT>python -m site
sys.path = [
? ? 'C:\\PYQT',
? ? 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.13_3.13.752.0_x64__qbz5n2kfra8p0\\python313.zip',
? ? 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.13_3.13.752.0_x64__qbz5n2kfra8p0\\DLLs',
? ? 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.13_3.13.752.0_x64__qbz5n2kfra8p0\\Lib',
? ? 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.13_3.13.752.0_x64__qbz5n2kfra8p0',
? ? 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.13_3.13.752.0_x64__qbz5n2kfra8p0\\Lib\\site-packages',
]
USER_BASE: 'C:\\PYQT' (exists)
USER_SITE: 'C:\\PYQT\\Python313\\site-packages' (doesn't exist)
ENABLE_USER_SITE: True
然后重新操作再安裝一遍
C:\PYQT>pip install pyqt6
C:\PYQT>pip install pyqt6_plugins-6.4.2.2.3-py3-none-any.whl
C:\PYQT>pip install pyqt6-tools
后續更改vscode中的兩個路徑(vscode中pyqt integration)
C:\PYQT\Python313\Scripts
C:\PYQT\Python313\site-packages\qt6_applications\Qt\bin