【发布时间】:2016-08-16 09:15:37
【问题描述】:
我用 pycharm 在 python 中编写了一个简单的脚本。在这个脚本中,我使用 tkinter。如果我在 pycharm 中运行脚本一切正常,但如果我使用带有命令 python script.py 的 shell 运行脚本,我会收到错误
ImportError: 没有名为 tkinter 的模块
【问题讨论】:
标签: python python-3.x pycharm python-3.4
我用 pycharm 在 python 中编写了一个简单的脚本。在这个脚本中,我使用 tkinter。如果我在 pycharm 中运行脚本一切正常,但如果我使用带有命令 python script.py 的 shell 运行脚本,我会收到错误
ImportError: 没有名为 tkinter 的模块
【问题讨论】:
标签: python python-3.x pycharm python-3.4
PyCharm 和您的系统 python 解释器可能安装了不同的版本和不同的模块。 检查 PyCaharm python 版本并默认使用它或只写完整的版本名称。例如:
python3.4 script.py
【讨论】:
python3.4 script.py,我会收到同样的错误Traceback (most recent call last): File "script.py", line 1, in <module> from tkinter import * File "/usr/local/lib/python3.4/tkinter/__init__.py", line 38, in <module> import _tkinter # If this fails your Python may not be configured for Tk ImportError: No module named '_tkinter'
tkinter 重命名为Tkinter。 Found here
ImportError: 没有名为 tkinter 的模块
简单地说,名为tkinter 的模块对于您用于运行脚本的python 二进制文件是不可见的。可能需要调查的领域
tkinter。这样您可能需要安装它。tkinter 打包在python 二进制文件中,检查shell 上的运行import tkinter,如果你最终得到错误import _tkinter # If this fails your Python may not be configured for Tk,那么你需要重新构建你的python。请查看this post here 了解更多详情。【讨论】:
phate@debian:~$ python3.4 Python 3.4.2 (default, May 5 2016, 23:18:17) [GCC 4.9.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import tkinter Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.4/tkinter/__init__.py", line 38, in <module> import _tkinter # If this fails your Python may not be configured for Tk ImportError: No module named '_tkinter' PS:如果我写了一些脚本并使用 github 与社区分享,我该怎么做