GDB:ModuleNotFoundError:没有名为“ _tkinter”的模块

时间:2020-07-05 16:59:42

标签: python tkinter gdb

因此,我试图调试在Python ctypes gdb: break in shared library loaded by python中运行的C代码。 但是,每当我运行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执行时它不起作用: enter image description here 为什么它可以在终端上运行但不能在gdb上运行?

2 个答案:

答案 0 :(得分:1)

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

➜  ~ 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
>>> 

答案 1 :(得分:0)

我遇到同样的错误。升级您的Python版本。希望对您有用