Ubuntu 无法更新 psutil 的问题

0x0 问题

编写 tmux-system-info 的时候,有依赖到高版本 psutil 里的接口功能。

因为发现 Ubuntu 系统里已经安装的 psutil 版本太低,所以准备升级一下:

sudo pip3 install --upgrade psutil

没想到,升级遇到了以下问题:

Collecting psutil
  Downloading psutil-5.7.0.tar.gz (449 kB)
     |████████████████████████████████| 449 kB 1.3 MB/s
Building wheels for collected packages: psutil
  Building wheel for psutil (setup.py) ... done
  Created wheel for psutil: filename=psutil-5.7.0-cp35-cp35m-linux_x86_64.whl size=266930 sha256=d58c92ec6957c1cd803740b507bcb2cc773de126d1c84e6b2a6cef24d3d691ff
  Stored in directory: /tmp/pip-ephem-wheel-cache-b_kxa327/wheels/bf/8a/50/4becf3b59de9aae0750147dfbf2f23470c9670c7c31c00df19
Successfully built psutil
Installing collected packages: psutil
  Attempting uninstall: psutil
    Found existing installation: psutil 3.4.2
ERROR: Cannot uninstall 'psutil'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

0x1 原因

经过研究,发现系统里的 psutil 是通过 apt 安装的:

sudo apt list --installed | grep psutil

python3-psutil/xenial-updates,xenial-security,now 3.4.2-1ubuntu0.1 amd64 [installed,automatic]

这就导致了 pip3 提示无法卸载和更新。

0x2 解决办法

  1. 使用 apt remove 掉 python3-psutil
  2. pip3 重新安装即可

Read More: