【问题标题】:matplotlib - no module named tkinter in Blender pythonmatplotlib - Blender python中没有名为tkinter的模块
【发布时间】:2018-02-09 06:41:21
【问题描述】:

我正在尝试编写一个需要matplotlib.pyplotblender 脚本。尝试import matplotlib.pyplot as plt 时出现以下错误:

ImportError: No module named 'tkinter'

但是,使用安装的anaconda版本,导入是没有问题的。常用solution运行

sudo apt-get install python3-tk

不能解决问题。 我尝试将路径添加到tkinter

sys.path.append('/usr/lib/python3.4/tkinter/')

sys.path.append('/home/<username>/anaconda3/lib/python3.6/tkinter/')

这两个命令都没有解决错误。

【问题讨论】:

  • 您是否尝试使用 pip 安装 tkinter:“pip install tkinter”
  • 我不知道这是可能的。使用tkinterpython3-tk 都会导致Could not find a version that satisfies the requirement tkinter (from versions: ) No matching distribution found for tkinter
  • 这是 tkinter,不是 tkiter
  • 对不起。只是一个错字。但是来自pip 的相同错误消息。我读到了,因为它是一个C++ 包,它不能通过pip 安装。
  • 我正在使用 anaconda 发行版,它运行良好,没有上述问题 :)

标签: python tkinter blender


【解决方案1】:

在 Linux 上,您无需使用 pip 来安装 tkinter,因为它是一个标准的 Python 模块。此外,Blender 包应该使用系统 Python,因此它可以访问所有系统 Python 模块。

但是 ... tkinter 是一个 GUI 框架,尝试使用它会与 Blender 自己的 GUI 冲突。

另一种选择可能是在屏幕外绘图模式下使用 Matplotlib,这不需要 GUI。

【讨论】:

    【解决方案2】:

    尝试将后端从 tkinter 切换到 agg 使用 -

    matplotlib.use('agg')

    【讨论】:

      【解决方案3】:

      正如我在这里解释的那样,我设法从 Blender 导入 tkinter(并将其与 matplotlib.pyplot 一起使用):

      https://stackoverflow.com/a/56050748/4511978

      希望对您有所帮助!
      安德烈斯

      【讨论】:

        猜你喜欢
        • 2016-07-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-07-15
        • 2016-12-29
        • 2014-11-27
        • 2016-04-30
        相关资源
        最近更新 更多