我正在嘗試揭穿 Ubuntu 22.04 上 PyQt5 的真正混亂,似乎我已經達到了無法卸載它的地步,我想知道為什麼確切地說這是不可能的,引發了以下錯誤:
$ sudo -H pip3 uninstall PyQt5
Found existing installation: PyQt5 5.15.6
ERROR: Cannot uninstall PyQt5 5.15.6, RECORD file not found. Hint: The package was installed by sip-build.
安裝的檔案有:
$ ls /usr/local/lib/python3.10/dist-packages/PyQt5
Qt5 sip.cpython-310-x86_64-linux-gnu.so
更多資訊:
$ sudo -H pip3 list | grep -i qt
PyQt5 5.15.6
PyQt5-Qt5 5.15.2
PyQt5-sip 12.11.0
PyQtWebEngine 5.15.5
QtAwesome 1.1.1
qtconsole 5.3.0
QtPy 2.2.0
sphinxcontrib-qthelp 1.0.3
我怎麼能正確卸載自訂 PyQt5 (在 /usr/local/lib/python3.10/dist-packages/ 下,注意當地的部分)?
這並不是要刪除,/usr/lib/python3/dist-packages/PyQt5
因為該資料夾是系統套件管理器用於安裝官方 apt 套件的資料夾python3-pyqt5
。事實上,這樣做會破壞許多其他東西:
$ sudo apt-get autoremove --purge python3-pyqt5
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
fonts-lyx* grass-core* grass-doc* libassimp5* libclang1-14* libdraco4* libfcgi-bin* libfcgi0ldbl* libjs-leaflet* liblaszip8* liblbfgsb0* libpdal-base13* libpdal-plugin-draco* libpdal-plugin-e57*
libpdal-plugin-faux* libpdal-plugin-hdf* libpdal-plugin-i3s* libpdal-plugin-icebridge* libpdal-plugin-pgpointcloud* libpdal-plugins* libpdal-util13* libqca-qt5-2* libqca-qt5-2-plugins* libqgis-3d3.26.2*
libqgis-analysis3.26.2* libqgis-app3.26.2* libqgis-core3.26.2* libqgis-customwidgets* libqgis-gui3.26.2* libqgis-native3.26.2* libqgis-server3.26.2* libqgisgrass7-3.26.2* libqgispython3.26.2*
libqscintilla2-qt5-15* libqscintilla2-qt5-l10n* libqt53danimation5* libqt53dcore5* libqt53dextras5* libqt53dinput5* libqt53dlogic5* libqt53dquickscene2d5* libqt53drender5* libqt5charts5* libqt5concurrent5*
libqt5designer5* libqt5designercomponents5* libqt5help5* libqt5keychain1* libqt5location5* libqt5opengl5* libqt5pdf5* libqt5positioningquick5* libqt5qml5* libqt5qmlmodels5* libqt5quick5* libqt5quickwidgets5*
libqt5sensors5* libqt5sql5* libqt5sql5-sqlite* libqt5test5* libqt5webchannel5* libqt5webengine-data* libqt5webengine5* libqt5webenginecore5* libqt5webenginewidgets5* libqt5webkit5* libqwt-qt5-6* libre2-9*
libspatialindex6* libsqlite3-mod-spatialite* libxsimd-dev* libzip4* pyqt5-dev-tools* python-babel-localedata* python-matplotlib-data* python3-babel* python3-beniget* python3-brotli* python3-cycler*
python3-decorator* python3-fonttools* python3-fs* python3-gast* python3-ipython-genutils* python3-jinja2* python3-jsonschema* python3-jupyter-core* python3-kiwisolver* python3-lz4* python3-matplotlib*
python3-mpmath* python3-nbformat* python3-owslib* python3-pbr* python3-plotly* python3-ply* python3-psycopg2* python3-pyproj* python3-pyqt5* python3-pyqt5.qsci* python3-pyqt5.qtpositioning*
python3-pyqt5.qtsql* python3-pyqt5.qtsvg* python3-pyqt5.qtwebchannel* python3-pyqt5.qtwebengine* python3-pyqt5.qtwebkit* python3-pyrsistent* python3-pythran* python3-qgis* python3-qgis-common* python3-scipy*
python3-sip* python3-sympy* python3-tenacity* python3-traitlets* python3-ufolib2* python3-unicodedata2* qdoc-qt5* qgis* qgis-common* qgis-plugin-grass* qgis-plugin-grass-common* qgis-provider-grass*
qgis-providers* qgis-providers-common* qhelpgenerator-qt5* qml-module-qtcharts* qt3d-assimpsceneimport-plugin* qt3d-defaultgeometryloader-plugin* qt3d-gltfsceneio-plugin* qt3d-scene2d-plugin* qt5-assistant*
qt5-image-formats-plugin-pdf* qtattributionsscanner-qt5* qttools5-dev-tools* unicode-data*
0 upgraded, 0 newly installed, 136 to remove and 0 not upgraded.
After this operation, 1’060 MB disk space will be freed.
Do you want to continue? [Y/n] n
Abort.
我總是被告知並習慣使用 標誌-H
,sudo
以便包不會與 所安裝的包重疊apt
,將它們安裝在/usr/local/lib/...
路徑中而不是 中/usr/lib/...
,但是使用 PyQt5,卸載命令似乎想卸載包apt
......為什麼?因為如果我手動刪除其中的 PyQT5 資料夾/usr/local/lib/...
:
$ sudo rm -rf /usr/local/lib/python3.10/dist-packages/PyQt5*
然後嘗試重做安裝,我面臨同樣的錯誤,但更加冗長:
$ sudo -H pip3 install -U PyQt5
Requirement already satisfied: PyQt5 in /usr/lib/python3/dist-packages (5.15.6)
Collecting PyQt5
Using cached PyQt5-5.15.7-cp37-abi3-manylinux1_x86_64.whl (8.4 MB)
Collecting PyQt5-sip<13,>=12.11
Using cached PyQt5_sip-12.11.0-cp310-cp310-manylinux1_x86_64.whl (359 kB)
Collecting PyQt5-Qt5>=5.15.0
Using cached PyQt5_Qt5-5.15.2-py3-none-manylinux2014_x86_64.whl (59.9 MB)
Installing collected packages: PyQt5-Qt5, PyQt5-sip, PyQt5
Attempting uninstall: PyQt5
Found existing installation: PyQt5 5.15.6
ERROR: Cannot uninstall PyQt5 5.15.6, RECORD file not found. Hint: The package was installed by sip-build.
但如果沒有-U
( --upgrade
) 標誌,它就可以很好地工作:
$ sudo -H pip3 install PyQt5
Requirement already satisfied: PyQt5 in /usr/lib/python3/dist-packages (5.15.6)
Collecting PyQt5-sip<13,>=12.8
Using cached PyQt5_sip-12.11.0-cp310-cp310-manylinux1_x86_64.whl (359 kB)
Installing collected packages: PyQt5-sip
Successfully installed PyQt5-sip-12.11.0
這實際上創建了我們之前手動刪除的資料夾:/usr/local/lib/python3.10/dist-packages/PyQt5/
相同的過程適用於許多其他 Python 套件,但顯然不適用於 PyQt5。
例如,對於 numpy,我有
/usr/lib/python3/dist-packages/numpy/
(1.21.5)和
/usr/local/lib/python3/dist-packages/numpy/
(1.23.2)。