首页 > 解决方案 > ImportError:无法导入名称仅在从 atom 运行文件时

问题描述

给定目录/khwarizmi上的两个文件,例如/khwarizmi/linear.py/khwarizmi/exceptions.py,当通过操作系统命令行(Ubuntu 18.04)运行脚本时,从另一个导入函数和类没有问题。然而,当我从 Atom 运行脚本时(无论是来自Hydrogen、 thepython-run还是script包,我得到

  Traceback (most recent call last):
  File "/home/santiago/Documentos/ScriptLab/Repos/khwarizmi/khwarizmi/linear.py", line 1, in <module>
    from exceptions import (InvalidFormError, LinearSolutionError,
ImportError: cannot import name InvalidFormError
[Finished in 0.074s]

这是导入的编写方式:

 from exceptions import (InvalidFormError, LinearSolutionError,
                        RedundantConversionError)

# The following are other imports that, provided
# they were executed, raise the same error.

import equations
from equations import operators
from lib.misc import cond_assign, num

我尝试调整看起来相关的软件包设置;例如,将Default CWD设置从第一个项目目录更改为脚本的项目目录或脚本的目录,但这并没有改变任何东西。

我的问题是,为什么从 Atom 包运行脚本时这不起作用,但从命令行运行?

(如果您想查看存储库的结构或完整代码,请参阅:https ://github.com/lpereyrasantiago/khwarizmi )

标签: pythonimportatom-editorimporterror

解决方案


exceptions 是一个 python 标准模块。如果您对私有模块使用相同的名称,这可能会混淆。


推荐阅读