【问题标题】:GDB: ModuleNotFoundError: No module named '_tkinter'GDB:ModuleNotFoundError:没有名为“_tkinter”的模块
【发布时间】:2020-10-25 20:26:34
【问题描述】:

所以我正在尝试调试我在 Python ctypes 中运行的 C 代码:gdb: break in shared library loaded by python。 但是,每当我运行 gdb 时,都会出现以下错误:ModuleNotFoundError: No module named '_tkinter'。我知道有很多关于这个错误的问题:matplotlib error - no module named tkinterImportError: No module named 'Tkinter'。我尝试了以下方法:

sudo apt-get install python-tk

sudo apt-get install python3-tk

从 Ubuntu 命令行执行时它工作得非常好:brandon@DESKTOP-V5LTF5T:~$ python3 MainApp.py 但是从 gdb 执行时它不起作用: 为什么它可以从终端运行,而不是 gdb?

【问题讨论】:

  • 如果gdb 可以与tkinter 一起使用,我认为原因是你有两个不同版本的python。但是gdb 会使用你没有使用的另一个版本的python' t 安装tkinter .
  • @jizhihaoSAMA,有可能,见附上的第一个链接。我使用使用 python 3.6.9 的“python3”参数运行 gdb,我在上面的图片中安装了 tkinter
  • 为了排除这种可能性,您可以尝试在终端中使用which python3 来检查路径。

标签: python tkinter gdb


【解决方案1】:

我面临同样的错误。升级你的 Python 版本。我希望这对你有用

【讨论】:

    【解决方案2】:

    您已经为您的 python3 安装安装了tkinter,但是您正在从 GDB 运行python3-dbg。幸运的是,解决方案很简单:为调试解释器安装 tkinter (python3-tk-dbg):

    ➜  ~ python3-dbg
    Python 3.6.9 (default, Apr 18 2020, 01:56:04) 
    [GCC 8.4.0] 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/lib/python3.6/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'
    >>> 
    
    ➜  ~ sudo apt install python3-tk-dbg 
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    The following NEW packages will be installed:
      python3-tk-dbg
    0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
    Need to get 0 B/509 kB of archives.
    After this operation, 1,441 kB of additional disk space will be used.
    Selecting previously unselected package python3-tk-dbg:amd64.
    (Reading database ... 205251 files and directories currently installed.)
    Preparing to unpack .../python3-tk-dbg_3.6.9-1~18.04_amd64.deb ...
    Unpacking python3-tk-dbg:amd64 (3.6.9-1~18.04) ...
    Setting up python3-tk-dbg:amd64 (3.6.9-1~18.04) ...
    
    ➜  ~ python3-dbg
    Python 3.6.9 (default, Apr 18 2020, 01:56:04) 
    [GCC 8.4.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import tkinter
    >>> 
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-03
      • 2015-10-30
      • 2020-03-06
      • 2018-09-15
      • 2021-12-14
      相关资源
      最近更新 更多