在python-docx
上为python3.5
安装了ubuntu 16.04
程序包。
软件包安装成功,pip3 show python-docx
给出:
Name: python-docx
Version: 0.8.10
Summary: Create and update Microsoft Word .docx files.
Home-page: https://github.com/python-openxml/python-docx
Author: Steve Canny
Author-email: [email protected]
License: The MIT License (MIT)
Location: /home/otariki/.local/lib/python3.5/site-packages
Requires: lxml
Required-by:
然后,我尝试将包导入到我的python文件中,例如:
import sys
sys.path.append('/home/otariki/.local/lib/python3.5/site-packages/docx')
from docx import Document
给出错误:ImportError: No module named 'docx'
我的错是什么?
您需要附加/home/otariki/.local/lib/python3.5/site-packages/
文件夹。为什么?程序包在文件夹docx
中(__init__.py
文件表示docx
是程序包)。
注意:请注意,默认情况下,$HOME/.local/lib/python3.5/site-packages/
文件夹应为PYTHONPATH
的一部分。我的意思是:您无需将该文件夹添加到sys.path
,它应该由Python自动完成。