网站搜索

删除 Arch Linux 中不属于任何软件包的冲突文件


今天,当我尝试在 Arch Linux 桌面上安装软件包时,我遇到了问题 - “错误:无法提交事务(冲突文件)”。当我尝试安装任何具有 Python 依赖项的包时,它不断抛出错误。以下是我尝试安装或更新任何软件包时的示例输出。

error: failed to commit transaction (conflicting files)
python-requests: /usr/lib/python3.6/site-packages/requests/__init__.py exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/__pycache__/__init__.cpython-36.pyc exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/__pycache__/_internal_utils.cpython-36.pyc exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/__pycache__/adapters.cpython-36.pyc exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/__pycache__/api.cpython-36.pyc exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/__pycache__/auth.cpython-36.pyc exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/__pycache__/certs.cpython-36.pyc exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/__pycache__/compat.cpython-36.pyc exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/__pycache__/cookies.cpython-36.pyc exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/__pycache__/exceptions.cpython-36.pyc exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/__pycache__/hooks.cpython-36.pyc exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/__pycache__/models.cpython-36.pyc exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/__pycache__/sessions.cpython-36.pyc exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/__pycache__/status_codes.cpython-36.pyc exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/__pycache__/structures.cpython-36.pyc exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/__pycache__/utils.cpython-36.pyc exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/_internal_utils.py exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/adapters.py exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/api.py exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/auth.py exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/certs.py exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/compat.py exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/cookies.py exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/exceptions.py exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/hooks.py exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/models.py exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/packages/__init__.py exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/packages/__pycache__/__init__.cpython-36.pyc exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/packages/idna/__init__.py exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/packages/idna/__pycache__/__init__.cpython-36.pyc exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/packages/idna/__pycache__/codec.cpython-36.pyc exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/packages/idna/__pycache__/compat.cpython-36.pyc exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/packages/idna/__pycache__/core.cpython-36.pyc exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/packages/idna/__pycache__/idnadata.cpython-36.pyc exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/packages/idna/__pycache__/intranges.cpython-36.pyc exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/packages/idna/__pycache__/uts46data.cpython-36.pyc exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/packages/idna/codec.py exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/packages/idna/compat.py exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/packages/idna/core.py exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/packages/idna/idnadata.py exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/packages/idna/intranges.py exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/packages/idna/uts46data.py exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/sessions.py exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/status_codes.py exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/structures.py exists in filesystem
python-requests: /usr/lib/python3.6/site-packages/requests/utils.py exists in filesystem
Errors occurred, no packages were upgraded.

在 Arch Linux wiki 页面上进行了一些搜索后,我发现原因可能是 - “pacman 已检测到文件冲突,并且它不会为您覆盖文件”。当您的 Arch Linux 系统在 pacman 操作期间或之后直接关闭时,可能会出现这种错误。这给你留下了一个损坏的 pacman 数据库和空文件。

删除 Arch Linux 中不属于任何软件包的冲突文件

修复此错误的解决方案是使用命令强制 pacman 覆盖那些冲突的文件:

sudo pacman -S --force <package-name>

如果它没有帮助,您需要查找这些文件是否不属于任何包,然后您应该删除或重命名它们。

查找文件是否属于任何程序包,如下所示。就我而言,我运行了以下命令:

sudo pacman -Qo /usr/lib/python3.6/site-packages/requests/__init__.py

上面的命令将检查是否有任何包拥有 /usr/lib/python3.6/site-packages/requests/__init__.py 。

示例输出:

error: No package owns /usr/lib/python3.6/site-packages/requests/__init__.py

正如您在上面的示例中看到的,没有包拥有 __init__.py 文件。我检查了上面输出中的所有文件。它们都不属于任何包。因此,如果您发现任何不属于任何包的文件,只需重命名或删除这些文件即可。在删除它们之前,只需备份这些文件(即 /usr/lib/python3.6/site-packages/requests/ 目录中的所有文件),以便在出现问题时可以恢复它们。

就我而言,我备份 /usr/lib/python3.6/site-packages/requests/ 文件夹的所有内容。

cp -fr /usr/lib/python3.6/site-packages/requests/. backup/

然后,我删除了上面输出中的所有文件。

sudo /usr/lib/python3.6/site-packages/requests/__init__.py
[...]
sudo rm -fr /usr/lib/python3.6/site-packages/requests/utils.py

这次我可以毫无错误地安装该软件包。

资源:

  • https://wiki.archlinux.org/index.php/Pacman#Troubleshooting

相关文章