Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

どうしたの

上記状態で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で解決します

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした