Tkinter :“Python이 Tk 용으로 구성되지 않았을 수 있습니다.”
오늘은 Tkinter로 작업을 시작하고 싶었지만 몇 가지 문제가 있습니다.
Python 3.2 (r32:88445, Mar 28 2011, 04:14:07)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from tkinter import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.2/tkinter/__init__.py", line 39, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
그렇다면 Tkinter와 함께 작동하도록 Python 3.2를 어떻게 구성 할 수 있습니까?
http://wiki.python.org/moin/TkInter 에 따르면 :
"No module named _tkinter"로 실패하면이 모듈 (C로 구현 된 확장 모듈)을 포함하도록 Python 구성을 수정해야합니다. 수행 하지 편집 모듈 / 설치 (이 만료되었습니다). Tcl 및 Tk (RPM을 사용할 때 -devel RPM도 설치)를 설치하거나 Tcl / Tk가 설치된 올바른 위치를 가리 키도록 setup.py 스크립트를 편집해야 할 수 있습니다. 기본 위치에 Tcl / Tk를 설치하는 경우 "make"를 다시 실행하면 _tkinter 확장이 빌드됩니다.
Arch / Manjaro에서 패키지를 설치하십시오 tk.
sudo pacman -S tk
tk-develPython을 빌드하기 전에 (또는 비슷한 이름의 패키지)를 설치하십시오 .
pyenvUbuntu 16.04 에서이 작업을 수행하려면 다음을 수행 해야합니다.
$ sudo apt-get install python-tk python3-tk tk-dev
그런 다음 원하는 Python 버전을 설치하십시오.
$ pyenv install 3.6.2
그런 다음 tkinter를 잘 가져올 수 있습니다.
import tkinter
Python 2.7을 사용하는 Fedora에서 동일한 문제가 발생했습니다. 몇 가지 추가 패키지가 필요합니다.
sudo dnf install tk-devel tkinter
패키지를 설치 한 후이 hello-world 예제는 Python 2.7에서 제대로 작동하는 것 같습니다.
$ cat hello.py
from Tkinter import *
root = Tk()
w = Label(root, text="Hello, world!")
w.pack()
root.mainloop()
$ python --version
Python 2.7.8
$ python hello.py
X11 포워딩을 통해 다음과 같이 보입니다.
Python 3에서 모듈 이름은 소문자이고 다른 패키지가 필요할 수 있습니다.
from tkinter import *
파이썬 2.7.9에서이 문제가 발생했습니다.
이 문제를 해결하기 위해 tk와 tcl을 설치 한 다음 파이썬 코드를 다시 빌드하고 다시 설치하고 구성하는 동안 다음과 같이 명시 적으로 tk 및 tcl의 경로를 설정했습니다.
./configure --with-tcltk-includes="-I/usr/include" --with-tcltk-libs="-L/usr/lib64 -ltcl8.5 -L/usr/lib64 -ltk8.5"
또한 Python 설치 프로세스에 대한 전체 기사 : 소스에서 Python 빌드
오, 방금 Ignacio Vazquez-Abrams가 파이썬을 빌드하기 전에 tk-dev를 설치하는 것을 제안한 솔루션을 따랐습니다. (Ubuntu 16.04의 소스에서 Python-3.6.1 빌드)
어제 빌드 한 미리 컴파일 된 개체와 바이너리가 있었지만 개체를 정리하지 않고 동일한 빌드 경로에서 다시 빌드했습니다. 그리고 그것은 아름답게 작동합니다.
sudo apt install tk-dev
(On the python build path)
(No need to conduct 'make clean')
./configure
make
sudo make install
그게 다야!
sudo apt-get install python3-tk
To anyone using Windows and Windows Subsystem for Linux, make sure that when you run the python command from the command line, it's not accidentally running the python installation from WSL! This gave me quite a headache just now. A quick check you can do for this is just
which <python command you're using>
If that prints something like /usr/bin/python2 even though you're in powershell, that's probably what's going on.
I think the most complete answer to this is the accepted answer found here:
How to get tkinter working with Ubuntu's default Python 2.7 install?
I figured it out after way too much time spent on this problem, so hopefully I can save someone else the hassle.
I found this old bug report deemed invalid that mentioned the exact problem I was having, I had Tkinter.py, but it couldn't find the module _tkinter: http://bugs.python.org/issue8555
I installed the tk-dev package with apt-get, and rebuilt Python using ./configure, make, and make install in the Python2.7.3 directory. And now my Python2.7 can import Tkinter, yay!
I'm a little miffed that the tk-dev package isn't mentioned at all in the Python installation documentation.... below is another helpful resource on missing modules in Python if, like me, someone should discover they are missing more than _tkinter.
This symptom can also occur when a later version of python (2.7.13, for example) has been installed in /usr/local/bin "alongside of" the release python version, and then a subsequent operating system upgrade (say, Ubuntu 12.04 --> Ubuntu 14.04) fails to remove the updated python there.
To fix that imcompatibility, one must
a) remove the updated version of python in /usr/local/bin;
b) uninstall python-idle2.7; and
c) reinstall python-idle2.7.
If you're running on an AWS instance that is running Amazon Linux OS, the magic command to fix this for me was
sudo yum install tkinter
If you want to determine your Linux build, try cat /etc/*release
You need to install tkinter for python3.
On Fedora pip3 install tkinter --user returns Could not find a version that satisfies the requirement... so I have to command: dnf install python3-tkinter. This have solved my problem
참고 URL : https://stackoverflow.com/questions/5459444/tkinter-python-may-not-be-configured-for-tk
'IT TIP' 카테고리의 다른 글
| 대다 관계에서 NSPredicate 대소 문자를 구분하지 않는 일치 (0) | 2020.11.19 |
|---|---|
| Jquery $ .ajax가 도메인 간 호출에서 IE에서 실패합니다. (0) | 2020.11.19 |
| numpy를 사용하여 Python에서 TIFF (가져 오기, 내보내기) 작업 (0) | 2020.11.19 |
| 전환 후 제약 조건을 적용하는 iOS 8 UIPageViewController (0) | 2020.11.19 |
| Dagger2 종속성-Gradle (0) | 2020.11.19 |
