我收到导入错误。如何解决这个问题?

时间:2020-04-14 07:04:24

标签: python

我具有以下目录结构:

C:/Automation/Windows/bin/powerconfig/powerconfig.py
C:/Automation/Windows/modules/Pylog.py

我在以下目录中:

C:/Automation/Windows/

当我尝试从Windows目录(如Windows)运行powerconfig.py文件时

C:\Automation\Windows> pyhton \bin\powerconfig\powerconfig.py

我立即收到没有名为“ modules.Pylog”的模块的错误

Powerconfig.py包含类似的导入语句

from modules.Pylog import Pylog

所有目录都包含要考虑打包的__init__.py文件

即使我尝试通过将路径C:/Automation/Windows/添加到sys.path来修复错误,但仍然遇到相同的错误。

我不知道如何解决此错误。

1 个答案:

答案 0 :(得分:0)

尝试在Powerconfig.py

中添加以下代码
import sys
sys.path.append("C:/Automation/Windows/")
from modules.Pylog import Pylog