首页 > 解决方案 > 使用 Thonny 调试时导入自定义 python 包时出错

问题描述

我正在学习在 python 中导入包,并在 Thonny IDE 中调试代码时遇到导入自定义包的问题。如果我只是运行程序,问题就不会出现。

我的相对目录结构是

编译\脚本\tesing_pkg_import.py

tesing_pkg_import.py 的内容是

import pandas as pd
def tes_func():
    #Checking for same column name in a single dataframe
    testDpCol = [ (11, 'jack', 34, 'Sydney', 5) ]
    testDfObj = pd.DataFrame(testDpCol, columns=['ID', 'Name', 'Age', 'Name', 'Experience'])
    print(testDfObj.head())

然后在编译文件夹中,我有 tesing_pkg_import_main.py 的内容是

import Scripts.tesing_pkg_import as test
test.tes_func()

我已验证

  1. 我的父路径存在于 syspath
  2. 程序运行成功
  3. 只有当我在 Thonny 中启动调试器时才会出现问题
  4. init .py 文件存在于 Compilation\Scripts\ 文件夹中

问题日志打印如下:

Traceback (most recent call last):
  File "D:\***Masked Manually*****\Compilation\tesing_pkg_import_main.py", line 1, in <module>
    import Scripts.tesing_pkg_import as test
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 851, in exec_module
  File "<frozen importlib._bootstrap_external>", line 988, in get_code
IndexError: list index out of range

任何帮助表示赞赏。

标签: pythondebuggingthonny

解决方案


似乎其他人也面临这个问题并在 github 上提出。

链接是发布是 https://github.com/thonny/thonny/issues/1920

该解决方案似乎也对我有用,快速调试正在使用 shift-F5 但正常调试在 Ctrl-F5 中不起作用。

任何需要帮助的人都可以在我提到的 git hub 链接上查看问题。


推荐阅读