Python脚本看不到我的模块

2024-06-01 04:17:55 发布

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

我有一个这样的项目:

panel/
   configure.py
   run.py
   panel/
      __init__.py
      mailer.py
      helpers/
         __init__.py
         gearman.py

mailer.py包括导入from helpers.gearman import ExceptionalGearmanWorkermailer.py还包含一个if __name__ == '__main__'检查,以便在从命令行调用时运行程序。在

从顶层panel/目录运行python panel/mailer.py。当我尝试运行这个时,mailer.py无法从gearman.py导入。具体的错误是

^{pr2}$

看起来像是直接从panel/内运行脚本不会将panel/添加到导入路径中?这是对的吗?我能做点什么吗?在


Tags: 项目runnamefrompyimportifinit