看來,如果一個文件被稱爲io.py
和它進口scipy.ndimage
,後者不知何故最終沒能找到自己的子模塊,也稱爲io
:Python和衝突的模塊名稱
$ echo "import scipy.ndimage" > io.py
$ python io.py
Traceback (most recent call last):
File "io.py", line 1, in <module>
import scipy.ndimage
File "/usr/lib/python2.7/dist-packages/scipy/__init__.py", line 70, in <module>
from numpy import show_config as show_numpy_config
File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 153, in <module>
from . import add_newdocs
File "/usr/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 22, in <module>
from .npyio import *
File "/usr/lib/python2.7/dist-packages/numpy/lib/npyio.py", line 4, in <module>
from . import format
File "/usr/lib/python2.7/dist-packages/numpy/lib/format.py", line 141, in <module>
import io
File "/tmp/rm_me/io.py", line 1, in <module>
import scipy.ndimage
File "/usr/lib/python2.7/dist-packages/scipy/ndimage/__init__.py", line 172, in <module>
from .filters import *
File "/usr/lib/python2.7/dist-packages/scipy/ndimage/filters.py", line 37, in <module>
from scipy.misc import doccer
File "/usr/lib/python2.7/dist-packages/scipy/misc/__init__.py", line 45, in <module>
from .common import *
File "/usr/lib/python2.7/dist-packages/scipy/misc/common.py", line 10, in <module>
from numpy import exp, log, asarray, arange, newaxis, hstack, product, array, \
ImportError: cannot import name exp
這是一個錯誤SciPy
,還是我使用Python錯了?
更新:我想象的那麼令人驚訝的行爲是如果mod1
解決路徑import mod2
相對於mod1
,而不是相對於任何人進口mod1
。
這不是SciPy中的錯誤;這正是Python導入工作的方式。話雖如此,我不知道除了調用你的模塊別的什麼解決方法。 – jangler
運行'python --version',看看你得到了什麼。 – user2357112
@ user2357112 2.7.6(Ubuntu-14.04的本機) – MaxB