2
2

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 1 year has passed since last update.

HomebrewでPython3を入れたときにpip3が入らなかったら

Last updated at Posted at 2021-11-11

Homebrewでpython3を入れようとした

$ brew install python3
 (中略)
==> /usr/local/Cellar/python@3.9/3.9.7_1/bin/python3 -m ensurepip
Last 15 lines from /Users/*/Library/Logs/Homebrew/python@3.9/post_install.01.python3:
 (中略)
subprocess.CalledProcessError: Command '['/usr/local/opt/python@3.9/bin/python3.9', '-c', '\nimport runpy\nimport sys\nsys.path = [\'/private/tmp/tmp7r1s7_i7/setuptools-57.4.0-py3-none-any.whl\', \'/private/tmp/tmp7r1s7_i7/pip-21.2.4-py3-none-any.whl\'] + sys.path\nsys.argv[1:] = [\'install\', \'--no-cache-dir\', \'--no-index\', \'--find-links\', \'/private/tmp/tmp7r1s7_i7\', \'setuptools\', \'pip\']\nrunpy.run_module("pip", run_name="__main__", alter_sys=True)\n']' returned non-zero exit status 1.
Warning: The post-install step did not complete successfully
You can try again using:
  brew postinstall python@3.9

python自体は使えるが、正常に完了しない

そして、pipを使おうとすると

$ pip3 -V
pip 19.0.3 from /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/site-packages/pip (python 3.7)

思ってたのと違う……

#結論
https://pip.pypa.io/en/stable/installation/
ここに書いてあった

$ python3 -m ensurepip

これで~/Library/Python/3.9/binにpipがインストールされる

再度pythonインストール

$ brew reinstall python3

こんどは正常にインストール完了し、/usr/local/bin/にもシンボリックリンクが作成される
(再インストールしないでも普通に$ brew postinstall python@3.9でよかったかもしれない)

$ pip3 -V
pip 21.2.4 from /Users/*/Library/Python/3.9/lib/python/site-packages/pip (python 3.9)

pipのアップデートもしておきましょう

$ pip3 install --upgrade pip
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pip in ./Library/Python/3.9/lib/python/site-packages (21.2.4)
Collecting pip
  Using cached pip-21.3.1-py3-none-any.whl (1.7 MB)
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 21.2.4
    Uninstalling pip-21.2.4:
      Successfully uninstalled pip-21.2.4
Successfully installed pip-21.3.1

参考になったが今回の解決法とは違っていた情報たち
https://ja.stackoverflow.com/questions/44308/homebrewでpython3をインストールするとpipが使えない
https://stackoverflow.com/questions/47255517/brew-install-python3-didnt-install-pip3

2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?