【发布时间】:2016-08-31 11:11:47
【问题描述】:
当我在我的 Python 项目(导入用户定义的包)中构建或调试特定文件时,我收到导入错误。我该如何解决这个问题?
test.py
def sum(a,b):
return a+b
test2.py
from test import sum
sum(3,4)
以上代码会出现导入错误cannot import test。
目录树
├── graphs
│ ├── Dijkstra's\ Algorithm.py
│ ├── Floyd\ Warshall\ DP.py
│ ├── Kruskal's\ algorithm.py
│ ├── Prim's\ Algoritm.py
│ ├── __init__.py
│ └── graph.py
├── heap
│ ├── __init__.py
│ ├── heap.py
│ └── priority_queue.py
尝试在图表中导入;
from heap.heap import Heap
【问题讨论】:
-
你能显示你的目录树吗?
-
@shutdown-hnow 添加目录结构