LoginSignup
2
2
記事投稿キャンペーン 「2024年!初アウトプットをしよう」

Homebrewのpyenvでinstallできない問題

Last updated at Posted at 2024-01-17

はじめに

想定読者

Pythonの仮想環境を作ろうとしてMacのpyenv install x.x.xでインストールしようとしたけどうまくいかない人

  • PC
    • MacBook Air (M1, 2020)
  • OS
    • MacOS Sonoma 14.2.1

状況

Djangoでアプリを作ろうと思って、pyenv + venvで仮想環境で環境構築をしようとして、

zsh
$ pyenv install 3.11.3

とすると、

出力結果
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.11.3.tar.xz...
-> https://www.python.org/ftp/python/3.11.3/Python-3.11.3.tar.xz

という感じで固まってしまっていました。
もともとpyenvは依存パッケージが多いらしく、brewで以下のパッケージはすでにインストールしてはいたのですが…。

zsh
$ brew install openssl readline sqlite3 xz zlib

解決法

とりあえずbrewで再インストールしてみる。

zsh
$ brew reinstall openssl readline sqlite3 xz zlib

一応brew自身もpyenvと一緒にアップデートしておく。

zsh
$ brew update
$ brew upgrade pyenv

そうしてもう一度、

出力結果
$ pyenv install 3.11.3
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.11.3.tar.xz...
-> https://www.python.org/ftp/python/3.11.3/Python-3.11.3.tar.xz
Installing Python-3.11.3...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/ryota/.pyenv/versions/3.11.3/lib/python3.11/tkinter/__init__.py", line 38, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
    ^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named '_tkinter'
WARNING: The Python tkinter extension was not compiled and GUI subsystem has been detected. Missing the Tk toolkit?

たぶんWARNINGなのでインストールはできたけど、依存関係がまだ微妙な感じっぽいっすね…。
Tk toolkitってやつが足りないらしいですので入れてみます。

zsh
$ brew install tcl-tk

もう一回インストールしてみてエラーが出ないか確認。

zsh
pyenv install 3.11.3                           
出力結果
pyenv: /Users/[username]/.pyenv/versions/3.11.3 already exists
continue with installation? (y/N) y
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.11.3.tar.xz...
-> https://www.python.org/ftp/python/3.11.3/Python-3.11.3.tar.xz
Installing Python-3.11.3...
python-build: use tcl-tk from homebrew
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.11.3 to /Users/[username]/.pyenv/versions/3.11.3

普通にできましたね。

zsh
pyenv versions
* system (set by /Users/[username]/.pyenv/version)
  3.11.3

ちゃんとこっちも確認できました。

あとがき

やはりpyenv周りの環境構築はいろいろ手こずるようで、QiitaやZennで似たような記事がありました。僕もいろんな記事を見てみたのですが、自分のようなトラブルが見つからなかったので、書き留めておきます。誰かの役に立てば幸いです。

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