scandir上的ImportError

时间:2016-10-05 02:39:57

标签: python-2.7 importerror scandir

我正在尝试使用scandir package替代python 2.7中的os.walk。但是,在导入期间,会引发ImportError,如下所示。

Python 2.7.12 (default, Jul  1 2016, 15:12:24) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> from scandir import scandir, walk
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "scandir.py", line 2, in <module>
    from scandir import walk
ImportError: cannot import name walk

在广泛搜索并且在这一点上非常难倒之后,我找不到任何对此错误的引用(除了循环导入之外)。任何帮助深表感谢 !

1 个答案:

答案 0 :(得分:0)

您在当前工作目录中有一个名为scandir.py的文件。

重命名它,让sys.path中的scandir发挥其魔力。