python - 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 )
解决方案
exceptions 是一个 python 标准模块。如果您对私有模块使用相同的名称,这可能会混淆。
推荐阅读
- typescript - 从 TypeScript 2.9.2 中的条件类型推断
- symfony - Symfony4 双实体创建
- variables - NetLogo 3D:在运行结束时打印多个海龟变量以输出并通过 BehaviorSpace 运行
- pipenv - 如何升级 pipenv 包并忽略预发布包?
- c# - 使用 MediaCapture 的相机流在一段时间后停止工作?
- python - 如何从 NetworkX 图形转换为 ete3 树对象?
- php - Laravel 贪吃 http
- r - 自定义函数不从magicfor返回for循环的结果
- string - 将匿名函数扩展为字符串
- uml - 从(流)端口到 UML 活动图的模型数据流