2017-03-24 255 views
0

從tethne進口槌在我的Python項目中,我一直在說:錯誤蟒蛇

from tethne.model.corpus import mallet 

,但我的問題是,當我跑我的項目,我在pycharm控制檯中看到這些錯誤:

Traceback (most recent call last): 
    File "D:/Python-Workspace(s)/BehnazDemo/Demo.py", line 1, in <module> 
    from tethne.model.corpus import mallet 
    File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35-32\lib\site-packages\tethne-0.8-py3.5.egg\tethne\__init__.py", line 20, in <module> 
    from tethne.classes.paper import Paper 
    File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35-32\lib\site-packages\tethne-0.8-py3.5.egg\tethne\classes\paper.py", line 5, in <module> 
    from tethne.classes.feature import Feature, feature 
    File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35-32\lib\site-packages\tethne-0.8-py3.5.egg\tethne\classes\feature.py", line 20, in <module> 
    from itertools import chain, izip 
ImportError: cannot import name 'izip' 

我該如何解決這個問題?

謝謝。

回答

0

看來你使用Python3.x,所以代碼應該是:

try: 
    from itertools import izip as zip 
except ImportError: # Python3.x you can just use zip 
    pass 

或者:

from itertools import zip_longest 

Python 3裏不再有itertoolsizip,但內置zip與Python2.x中的izip的功能相同。

+0

我已經使用python 3.5,並且我還根據您的解決方案添加了zip_longest,並且使用了try - 除了再次運行後,我看到了同樣的錯誤,我已經添加到了我的問題中。你能幫助我嗎? – brelian

+0

@SiHa:我已經使用python 3.5,並且還根據您的解決方案添加了zip_longest,並且使用了try - 除了再次運行後,我看到了同樣的錯誤,我已經添加到了我的問題中。你能幫助我嗎? – brelian

+0

@brelian您應該從'itertools import chain,izip'中的''行中移除'izip'.順便說一下,您還可以在Github [tethne](https://github.com/diging/tethne)更多的支持。 – McGrady