2014-11-01 71 views
6

上週我將機器升級到了優勝美地。現在嘗試運行鵜鶘devserver當我得到一個ImportError:爲什麼我得到一個python ImportError:沒有名爲html_parser的模塊?

$ ./develop_server.sh start 
Starting up Pelican and HTTP server 
Traceback (most recent call last): 
    File "/usr/local/bin/pelican", line 7, in <module> 
    from pelican import main 
    File "/Library/Python/2.7/site-packages/pelican/__init__.py", line 20, in <module> 
    from pelican.generators import (ArticlesGenerator, PagesGenerator, 
    File "/Library/Python/2.7/site-packages/pelican/generators.py", line 23, in <module> 
    from pelican.readers import Readers 
    File "/Library/Python/2.7/site-packages/pelican/readers.py", line 24, in <module> 
    from six.moves.html_parser import HTMLParser 
ImportError: No module named html_parser 
/usr/bin/python: No module named html_parser 
Pelican didn't start. Is the Pelican package installed? 
Stale PID, deleting 
Stale PID, deleting 

我從REPL試圖做一個直接進口時,得到了同樣的錯誤,但將模塊安裝:

$ /usr/bin/python 
Python 2.7.6 (default, Sep 9 2014, 15:04:36) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import 
KeyboardInterrupt 
>>> from six.moves.html_parser import HTMLParser 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
ImportError: No module named html_parser 
>>> import six 
>>> six.moves.html_parser 
<module 'HTMLParser' from '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/HTMLParser.pyc'> 
>>> six.moves.html_parser.HTMLParser 
<class HTMLParser.HTMLParser at 0x10b751530> 
>>> 

上午我錯過了明顯的東西?這裏發生了什麼?

+0

您可能需要重新安裝鵜鶘 – jgritty 2014-11-01 19:16:26

回答

4

六庫使用了一些高級的進口魔法。 html_parser的進口必須以特殊方式完成。 from six.moves import html_parser通常有效。如果您有第三方代碼嘗試以其他方式從六個導入,則可以先導入six和/或six.moves,然後再導入其他任何東西。

+2

謝謝,我將這個問題提交給鵜鶘團隊,作爲bug – 2014-11-02 17:53:53

+1

我確認我在另一個項目上遇到同樣的問題,並且這種導入解決了問題。 – sorin 2015-01-30 19:43:04

+0

我沒有在我的代碼中使用這個html_parser,但是當我使用pyinstaller從我的代碼中創建二進制可執行文件時,它要求我導入html_parser ..可能是什麼原因..是否真的需要html_parser以防我們計劃使二進制可執行..請撕碎一些光..謝謝 – 2016-09-28 04:41:59

相關問題