我知道很多关于包内导入的问题。我想知道下面的内容是否也适用于Python 2.7。导入Python 2.7时出错
Source/
anomalyCheck/
__init__.py
DLthput.py
ULPowerStats.py
ULThput.py
config/
__init__.py
configure.py
parserTools/
__init__.py
logParser.py
utilities/
__init__.py
plotLogResults.py
__init__.py
lteDebugger.py
---- ---- lteDebugger.py
import parserTools.logParser
import anomalyCheck.DLthput
import utilities.plotLogResults
import configuration.TDDFDDconfiguration
import anomalyCheck.ULthput
### Work done after here ####
------ DLThput.py ------
from ..utilities.plotLogResults import *
from ..parserTools.logParser import *
### Work done after here ####
--- --- ULThput.py -------
from ..parserTools.logParser import *
from ..utilities.plotLogResults import *
错误:
在运行lteDebugger.py文件,错误的是
ValueError: Attempted relative import beyond toplevel package File "C:\Users\manojtut\Desktop\Project_LTE_SVN\Source\lteDebugger.py", line 2, in import anomalyChecker.DLthput File "C:\Users\manojtut\Desktop\Project_LTE_SVN\Source\anomalyChecker\DLthput.py", line 1, in
我读过几乎所有可用的文档和圭多的指南封装内进口。另外,我想我拥有一切正确的地方。我在这里错过了什么吗?请指出。提前致谢。 :) :)
编辑1:所提到的问题是由琥珀的答案解决。所以,lteDebugger.py通过导入所有其他模块正常工作。现在,另一个问题是,我无法解决的是,当我想编译/解释(无论你想调用)DLThput.py/ULthput.py,它显示与上述相同的错误。 。ValueError:试图超出顶层包的相对导入。我有任何解决方案,其他添加路径到sys黑客?我真的不想这么做,除非这是唯一要做的事情。 那么,我该如何躲避?
in“from ..utilities.plotLogResults import *”为什么你放回“..”?我想你仍然可以导入“从utilities.plotLogResults导入*” –
不,我不认为我可以。虽然会检查。 – VoodooChild92