2016-10-05 46 views
4

我試圖在0123中使用scandir package作爲python 2.7中的os.walk的替代方法。但是,在導入期間,ImportError會如下所示。scandir上的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

你給這個看看? https://github.com/benhoyt/scandir –

+1

@ JamM.HernandezQ。我正在嘗試使用您提到的模塊。我在virtualenv中使用'pip install scandir'安裝它。但是在安裝軟件包後,我得到了上述錯誤! –

+0

我是'scandir'軟件包的作者,這很奇怪。我現在試着用pip來安裝它,並且導入語句在Python 3.5和2.7上都能正常工作。如果你只是「輸入scandir」,會發生什麼?然後當你鍵入'scandir'(顯示模塊/源文件)時它說了什麼? –

回答

0

在當前工作目錄中有一個名爲scandir.py的文件。

重命名它,讓sys.path中的scandir發揮它的魔力。