5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Amazon Linux 2でpip3 をupdateするとpipが消失する

Posted at

#現象
Amazon Linux 2でyum -y install Python3すると標準でPython3.7とpip3のpip 9.0.3が入る (2019/8時点)

この状態rootのshellからpip3をそのままupdateすると死ぬ

# pip3 --version
pip 9.0.3 from /usr/lib/python3.7/site-packages (python 3.7)
# which pip3
/bin/pip3
# pip3 install -U pip
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Collecting pip
  Downloading https://files.pythonhosted.org/packages/30/db/9e38760b32e3e7f40cce46dd5fb107b8c73840df38f0046d8e6514e675a1/pip-19.2.3-py2.py3-none-any.whl (1.4MB)
    100% |????????????????????????????????| 1.4MB 905kB/s
Installing collected packages: pip
  Found existing installation: pip 9.0.3
    Uninstalling pip-9.0.3:
      Successfully uninstalled pip-9.0.3
Successfully installed pip-19.2.3
# pip
bash: pip: command not found
# pip3
bash: /bin/pip3: No such file or directory
# which pip3
/usr/bin/which: no pip3 in (/sbin:/bin:/usr/sbin:/usr/bin)
# which pip
/usr/bin/which: no pip in (/sbin:/bin:/usr/sbin:/usr/bin)

成功したと言われるがpipもpip3も存在しないと言われる。詰んだように見える

#原因
根本的な原因は pip3 本体が/usr/local/bin/に移動したため

# ls /usr/local/bin/ -la
total 12
drwxr-xr-x  2 root root  43 Aug 27 19:47 .
drwxr-xr-x 12 root root 131 Jun 18 22:23 ..
-rwxr-xr-x  1 root root 216 Aug 27 19:47 pip
-rwxr-xr-x  1 root root 216 Aug 27 19:47 pip3
-rwxr-xr-x  1 root root 216 Aug 27 19:47 pip3.7

そして、Amazon Linux 2 でsudo su等でrootになった場合、rootのPATHに/usr/local/binは含まれてない
(上のwhichにも書いてるけど/sbin:/bin:/usr/sbin:/usr/binしかない)
なお、ec2-userには含まれているのでrootになってなければ影響ない。sudo suしたら見えなくなるけど。

$ echo $PATH
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/ec2-user/.local/bin:/home/ec2-user/bin

#解決法

  1. sudo su とかせず常にsudo pip3でやる。pip3のupdate時にもrootで動かすなって書いてるし。
  2. /usr/local/binをPATHに追加する。とりあえずは解決する。
5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?