每次我尝试时都会收到一些错误apt-get install
,它告诉我无法这样做,因为某些包“不会被安装”。
我既无法安装这些软件包,也无法卸载它们,也无法卸载任何软件包。
当我这样做时,apt --fix-broken install
我收到错误“E:子进程 /usr/bin/dpkg 返回错误代码 (1)”
所讨论的包是 ROS Noetic 包,因此熟悉 ROS 安装会很有帮助。
$ sudo apt-get upgrade
[sudo] password for roth:
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
python3-rosdep-modules : Depends: python3-rospkg-modules (>= 1.3.0) but it is not installed
Depends: python3-catkin-pkg-modules (>= 0.4.0) but it is not installed
Depends: python3-rosdistro-modules (>= 0.7.5) but it is not installed
ros-noetic-rospack : Depends: python3-catkin-pkg-modules but it is not installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
$ sudo apt --fix-broken install
:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
python3-catkin-pkg-modules python3-rosdistro-modules python3-rospkg-modules
The following NEW packages will be installed:
python3-catkin-pkg-modules python3-rosdistro-modules python3-rospkg-modules
0 upgraded, 3 newly installed, 0 to remove and 101 not upgraded.
30 not fully installed or removed.
Need to get 0 B/98.0 kB of archives.
After this operation, 650 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 247423 files and directories currently installed.)
Preparing to unpack .../python3-catkin-pkg-modules_0.4.24-1_all.deb ...
Unpacking python3-catkin-pkg-modules (0.4.24-1) ...
dpkg: error processing archive /var/cache/apt/archives/python3-catkin-pkg-module
s_0.4.24-1_all.deb (--unpack):
trying to overwrite '/usr/lib/python3/dist-packages/catkin_pkg/__init__.py', wh
ich is also in package python3-catkin-pkg 0.4.24-1
Preparing to unpack .../python3-rospkg-modules_1.3.0-1_all.deb ...
Unpacking python3-rospkg-modules (1.3.0-1) ...
dpkg: error processing archive /var/cache/apt/archives/python3-rospkg-modules_1.
3.0-1_all.deb (--unpack):
trying to overwrite '/usr/lib/python3/dist-packages/rospkg/__init__.py', which
is also in package python3-rospkg 1.2.3-1
Preparing to unpack .../python3-rosdistro-modules_0.8.3-1_all.deb ...
Unpacking python3-rosdistro-modules (0.8.3-1) ...
dpkg: error processing archive /var/cache/apt/archives/python3-rosdistro-modules
_0.8.3-1_all.deb (--unpack):
trying to overwrite '/usr/lib/python3/dist-packages/rosdistro/__init__.py', whi
ch is also in package python3-rosdistro 0.8.0-1
Errors were encountered while processing:
/var/cache/apt/archives/python3-catkin-pkg-modules_0.4.24-1_all.deb
/var/cache/apt/archives/python3-rospkg-modules_1.3.0-1_all.deb
/var/cache/apt/archives/python3-rosdistro-modules_0.8.3-1_all.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
答案1
这是您需要查看的错误部分:
dpkg: error processing archive /var/cache/apt/archives/python3-catkin-pkg-module
s_0.4.24-1_all.deb (--unpack):
trying to overwrite '/usr/lib/python3/dist-packages/catkin_pkg/__init__.py', wh
ich is also in package python3-catkin-pkg 0.4.24-1
Preparing to unpack .../python3-rospkg-modules_1.3.0-1_all.deb ...
Unpacking python3-rospkg-modules (1.3.0-1) ...
dpkg: error processing archive /var/cache/apt/archives/python3-rospkg-modules_1.
3.0-1_all.deb (--unpack):
trying to overwrite '/usr/lib/python3/dist-packages/rospkg/__init__.py', which
is also in package python3-rospkg 1.2.3-1
Preparing to unpack .../python3-rosdistro-modules_0.8.3-1_all.deb ...
Unpacking python3-rosdistro-modules (0.8.3-1) ...
dpkg: error processing archive /var/cache/apt/archives/python3-rosdistro-modules
_0.8.3-1_all.deb (--unpack):
trying to overwrite '/usr/lib/python3/dist-packages/rosdistro/__init__.py', whi
ch is also in package python3-rosdistro 0.8.0-1
Errors were encountered while processing:
/var/cache/apt/archives/python3-catkin-pkg-modules_0.4.24-1_all.deb
/var/cache/apt/archives/python3-rospkg-modules_1.3.0-1_all.deb
/var/cache/apt/archives/python3-rosdistro-modules_0.8.3-1_all.deb
错误消息清楚地表明它正在尝试覆盖一些文件,因为有一个包已经创建了这些文件。简而言之,该包本应将其文件之一放在 中/usr/lib/python3/
,但它惊讶地发现这些文件已经在那里了。它不知道下一步该怎么做,所以它开始抛出错误消息。
如果你仔细看,你会看到这些包被放在 中
/var/cache/apt/archives/
。这是apt
的缓存目录,它会下载文件并等待 来dpkg
安装它们(处理它们)。由于它们存储在apt
的缓存中,你会看到每次使用 时apt
,dpkg
都会开始处理这些文件(包)。
如何解决这个问题?
您可以使用三种不同类型的命令来解决此问题:
用于
dpkg -P
清除软件包并安全地修复所有内容(几乎......)。意思
-P
是dpkg
将--purge
删除所有内容,包括设置和配置文件。对于您来说,您需要强制覆盖:
dpkg -i --force-overwrite /var/cache/apt/archives/python3-catkin-pkg-modules_0.4.24-1_all.deb dpkg -i --force-overwrite /var/cache/apt/archives/python3-rospkg-modules_1.3.0-1_all.deb dpkg -i --force-overwrite /var/cache/apt/archives/python3-rosdistro-modules_0.8.3-1_all.deb
然后运行:
sudo apt -f install
使用
dpkg -i --force-overwrite <file>
使其更安全。对于您来说,您需要强制覆盖:
dpkg -i --force-overwrite /var/cache/apt/archives/python3-catkin-pkg-modules_0.4.24-1_all.deb dpkg -i --force-overwrite /var/cache/apt/archives/python3-rospkg-modules_1.3.0-1_all.deb dpkg -i --force-overwrite /var/cache/apt/archives/python3-rosdistro-modules_0.8.3-1_all.deb
然后运行:
sudo apt -f install
用于
rm
删除这些包文件(有点危险)。您可以
.deb
通过运行以下命令删除所有这些包文件:sudo rm -r /var/cache/apt/archives/*.deb
然后运行:
sudo apt -f install
笔记:
- 仅使用其中一种方法。
- 推荐第 1 和第 2 个。
当心!
如果文件不同,覆盖可能会造成严重问题。冲突的软件包之一将无法正常运行。
当没有已安装的软件包依赖于某些依赖项时,未手动安装的依赖项将被删除。
一般来说,如果出现任何问题,则运行:
sudo apt install python3-all
可以工作(至少在 Ubuntu 21.10 上)