2017-06-22 169 views
0

當我做import docxpython-docx模塊,我得到這個錯誤:導入python-docx時出錯?

Traceback (most recent call last): 
    File "/Userpath/script.py", line 19, in <module> 
    import docx 
    File "/Library/Python/2.7/site-packages/docx/__init__.py", line 3, in <module> 
    from docx.api import Document # noqa 
    File "/Library/Python/2.7/site-packages/docx/api.py", line 14, in <module> 
    from docx.package import Package 
    File "/Library/Python/2.7/site-packages/docx/package.py", line 11, in <module> 
    from docx.opc.package import OpcPackage 
    File "/Library/Python/2.7/site-packages/docx/opc/package.py", line 12, in <module> 
    from .part import PartFactory 
    File "/Library/Python/2.7/site-packages/docx/opc/part.py", line 12, in <module> 
    from .oxml import serialize_part_xml 
    File "/Library/Python/2.7/site-packages/docx/opc/oxml.py", line 12, in <module> 
    from lxml import etree 
ImportError: dlopen(/Library/Python/2.7/site-packages/lxml/etree.so, 2): Library not loaded: libxslt.1.dylib 
    Referenced from: /Library/Python/2.7/site-packages/lxml/etree.so 
    Reason: unsafe use of relative rpath libxslt.1.dylib in /Library/Python/2.7/site-packages/lxml/etree.so with restricted binary 

任何想法是怎麼回事?

回答

2

這是安裝lxml時出現的問題。

我希望你在Python相同的答案,當你在該行中鍵入:

>>> from lxml import etree 

這意味着它不涉及python-docx,它只是試圖(正常與否)裝入一個包,這不是裝。

最好的辦法是在「Windows安裝LXML」並瞭解你可以搜索,但快速修復可能會卸載您有任何lxml,並使用從這裏一個二進制分發從頭開始重新安裝:http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml

+0

是,通過命令行發生同樣的錯誤,但即使卸載並重新安裝lxml後,問題仍然存在。我在Mac 10.11上,以供參考。 – user1917407

+0

可能沒有安裝libxml2和libxslt庫:https://stackoverflow.com/a/26544099/1902513 – scanny

+0

這也沒有解決問題:(。這兩個庫安裝成功,沒有錯誤,但原始ERROR與lxml相關並沒有改變 – user1917407