Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
15
Help us understand the problem. What is going on with this article?
@hokkun_dayo

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

More than 5 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で解決します

15
Help us understand the problem. What is going on with this article?
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
hokkun_dayo
Java, Kotlin 開発者。Web 界隈に生息。

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
15
Help us understand the problem. What is going on with this article?