LoginSignup
11
14

More than 5 years have passed since last update.

Mac OS X 10.11.3 (El Capitan) + pyenv + Python 3.5.1でimport tkinterできない時

Last updated at Posted at 2016-04-22

どうしたの

上記状態でpython起動し、import tkinterするとimport errorになる。
OS版のpythonについては情報があるものののこの組み合わせの情報はなかった(あんまり違わなかったけど)。

import tkinterすると

Traceback (most recent call last):
  File "/var/folders/_w/52jb4hnx4hb3rv6pvdlb7gtm0000gp/T/login.py", line 2, in <module>
    import tkinter as tk
  File "/Users/hogehoge/.pyenv/versions/3.5.1/lib/python3.5/tkinter/__init__.py", line 35, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named '_tkinter'

解決方法

% 一旦アンインストール
$ pyenv uninstall 3.5.1
% tcl-tkをインストール
$ brew tap Homebrew/dupes
$ brew install tcl-tk
% 再度インストール
$ pyenv install 3.5.1

これで無事使えました。brewでinstallしたpythonについては--with-brewed-tkが必要のようですが今回は特に明示する必要がありませんでした。

# zlibでハマってしまったけどこれはxcode-select --installで解決します

11
14
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
11
14