Python 2.7.9:无法从modu导入

2024-10-03 23:28:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我的目录结构如下所示:

Project
|+-- test.py
|
+>> agents
|  +-- __init__.py
|  +-- TestAgent.py
|    
+>> automation
|  +-- __init__.py
|  |
|  +>> navigators
|      +--__init__.py
|      +--SystemNavigator.py 

在“代理”下的“初始化”py中,我有以下代码:

^{2}$

在SystemNavigator中我有:

from agents import TestAgent

当我试图运行程序时,我得到:

Traceback (most recent call last):
File "test.py", line 1, in <module>
from navigators import SystemNavigator
File "/Users/jb/Desktop/code/tools/pythontest/automation/navigators/__init__.py", line 1, in <module>
from SystemNavigator import SystemNavigator
File "/Users/jb/Desktop/code/tools/pythontest/automation/navigators/SystemNavigator.py", line 1, in <module>
from agents import TestAgent
ImportError: No module named agents

我在一个单独的目录中设置了一个完全相同的文件结构来进行复查,并且我能够在那里实现这个功能。我阅读了堆栈溢出和其他地方。我想避免对系统路径或者更改我的目录结构。根据其他人的建议,我尝试删除目录中的.pyc文件,并删除/重新创建agents下的uinit_uu.py。在

有没有人建议我下一步在哪里进行故障排除?我真的很感激!在


Tags: infrompyimport目录initline结构