我正在尝试解决 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)。