无法在 Python3 中导入 tkinter,但它可以在 python2 (Python3.7 macOS Catalina) 中工作 [英] Unable to import tkinter in Python3, but it works in python2 (Python3.7 macOS Catalina)

查看:99
本文介绍了无法在 Python3 中导入 tkinter,但它可以在 python2 (Python3.7 macOS Catalina) 中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行 python3 将我带入 python,然后简单地运行 import tkinter 导致以下错误:

Running python3 to bring me into python, and then simply running import tkinter results in the following error:

File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/tkinter/__init__.py", line 36, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'

但是,当进入 python shell(不是 python3)时,import tkinter 可以正常工作.如何让 tkinter 与 Python3 一起工作?

However when going into the python shell (not python3), import tkinter works fine as expected. How can I get tkinter to work with Python3?

请注意以下事项:

  • 我使用的是 MacOS Catalina
  • 我正在使用 Python 3.7.3(基于 python3 --version)
  • 看起来我的 python3 可执行文件是 (/usr/bin/python3)
  • tkinter 的路径是 /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/tkinter/
  • 我可以在终端中运行 idle,但我无法运行 idle3
  • 我不认为我在使用 virtualenvpyenv 或类似的东西
  • I am on MacOS Catalina
  • I am working with Python 3.7.3 (based off python3 --version)
  • It looks like my python3 executable is (/usr/bin/python3)
  • The path for tkinter is /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/tkinter/
  • I am able to run idle in Terminal, but I can't run idle3
  • I don't think I am using a virtualenv or pyenv or anything like that

推荐答案

不要在import _tkinter

使用import tkinter

我相信这会奏效.如果有效,请勾选我的答案.

I am Sure that this will work. If it works then tick my answer.

这篇关于无法在 Python3 中导入 tkinter,但它可以在 python2 (Python3.7 macOS Catalina) 中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆