当我使用import 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
知道这里发生了什么吗?
答案 0 :(得分:2)
这是lxml
安装的问题。
我希望您在输入行时在Python中得到相同的答案:
>>> from lxml import etree
这意味着它与python-docx
无关,它只是尝试加载未安装(或未正确安装)的软件包。
最好的办法是搜索“安装lxml&#39;并了解你可以做什么,但快速解决方法可能是卸载你所拥有的lxml
并使用二进制发行版从头开始重新安装它:http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml