我遇到了这个奇怪的问题,我无法从Python中的数学模块导入。但是导入整个模块有效。
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
/Users/bdhammel/Documents/research_programming/analysis_routines/visar_analysis.py in <module>()
16
17 from core import scopes as cscopes
---> 18 from core import plot as cplot
19 from core.plot import ImageData, IndexSelector
20 from core.math import savitzky_golay
/Users/bdhammel/Documents/research_programming/core_diag/core/plot.py in <module>()
10 sys.path.append(CORE_DIR)
11
---> 12 from core import math as cmath
13
14 class ImageData(object):
/Users/bdhammel/Documents/research_programming/core_diag/core/math.py in <module>()
3 import sys
4 import math
----> 5 from math import factorial
6 from scipy.integrate import cumtrapz
7
ImportError: cannot import name factorial
我的目录结构是这样的
Main file
from math import factorial # works fine here
import custom_module
custom_module
import math # works fine
from math import factorial # breaks
我不知道为什么会这样。任何帮助,将不胜感激。
我在虚拟环境中工作。
答案 0 :(得分:1)
如果您要导入math
内的core.math
,请启用绝对导入,这样您就不会获得core.math
:
from __future__ import absolute_import