python - 使用 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()
我已验证
- 我的父路径存在于 syspath
- 程序运行成功
- 只有当我在 Thonny 中启动调试器时才会出现问题
- 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
任何帮助表示赞赏。
解决方案
似乎其他人也面临这个问题并在 github 上提出。
链接是发布是 https://github.com/thonny/thonny/issues/1920
该解决方案似乎也对我有用,快速调试正在使用 shift-F5 但正常调试在 Ctrl-F5 中不起作用。
任何需要帮助的人都可以在我提到的 git hub 链接上查看问题。
推荐阅读
- javascript - 有没有一种简单的方法可以在 Javascript 中完全冻结对象及其子对象(Deep Freeze)?
- excel - 减少单元格中的换行数/chr(10)
- pandas - Pandas read_csv 错误分隔符识别
- jquery - 为什么我只能检查复选框?
- python-3.x - 使用 sklearn 的 Imputer 时如何解决 DeprecationWarning
- c# - 在 C# 中压缩多个类似的 if 语句
- python - urllib.parse.urlparse 不读取参数
- bash - 从 SGE 作业提交中排除主机列表
- lua - 我的简单 Lua 脚本是否挂在第一个任务上?
- c++ - 在命令行运行 C++ 包的函数时出错