无法从 Python 中的 'math' 导入模块
Unable to import modules from 'math' in Python
我遇到了这个奇怪的问题,因为我无法从 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
我不知道为什么会这样。任何帮助,将不胜感激。
我在虚拟环境中工作。
如果您想在 core.math
中导入内置 math
,请打开绝对导入,这样您就不会得到 core.math
:
from __future__ import absolute_import
我遇到了这个奇怪的问题,因为我无法从 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
我不知道为什么会这样。任何帮助,将不胜感激。
我在虚拟环境中工作。
如果您想在 core.math
中导入内置 math
,请打开绝对导入,这样您就不会得到 core.math
:
from __future__ import absolute_import